/**
 * 级联数据源注册表
 * 集中管理所有预设级联数据源配置
 */
import { CascadeDataSourceType, type CascadeDataSourceRegistry } from './types';
import {
  environmentProjectsConfig,
  jenkinsServerViewsJobsConfig,
  departmentUsersConfig,
  departmentTreeConfig,
  projectGroupAppsConfig
} from './presets/cascade';

/**
 * 级联数据源配置注册表
 */
export const CASCADE_DATA_SOURCE_REGISTRY: CascadeDataSourceRegistry = {
  [CascadeDataSourceType.ENVIRONMENT_PROJECTS]: environmentProjectsConfig,
  [CascadeDataSourceType.JENKINS_SERVER_VIEWS_JOBS]: jenkinsServerViewsJobsConfig,
  [CascadeDataSourceType.DEPARTMENT_USERS]: departmentUsersConfig,
  [CascadeDataSourceType.DEPARTMENT_TREE]: departmentTreeConfig,
  [CascadeDataSourceType.PROJECT_GROUP_APPS]: projectGroupAppsConfig
};

/**
 * 获取级联数据源配置
 * @param type 级联数据源类型
 * @returns 级联数据源配置，如果不存在则返回 undefined
 */
export const getCascadeDataSourceConfig = (type: CascadeDataSourceType) => {
  return CASCADE_DATA_SOURCE_REGISTRY[type];
};

/**
 * 检查级联数据源类型是否已注册
 * @param type 级联数据源类型
 * @returns 是否已注册
 */
export const hasCascadeDataSource = (type: CascadeDataSourceType): boolean => {
  return type in CASCADE_DATA_SOURCE_REGISTRY;
};

/**
 * 获取所有已注册的级联数据源类型
 * @returns 级联数据源类型列表
 */
export const getAllCascadeDataSourceTypes = (): CascadeDataSourceType[] => {
  return Object.keys(CASCADE_DATA_SOURCE_REGISTRY) as CascadeDataSourceType[];
};

