/**
 * 数据源注册表
 * 集中管理所有预设数据源配置
 */
import { DataSourceType, type DataSourceRegistry } from './types';
import { jenkinsServersConfig } from './presets/jenkins';
import { k8sClustersConfig } from './presets/k8s';
import { gitRepositoriesConfig } from './presets/git';
import { dockerRegistriesConfig } from './presets/docker';
import { notificationChannelTypesConfig, notificationChannelsConfig } from './presets/notification';
import { usersConfig, rolesConfig, departmentsConfig } from './presets/user';

/**
 * 数据源配置注册表
 */
export const DATA_SOURCE_REGISTRY: DataSourceRegistry = {
  [DataSourceType.JENKINS_SERVERS]: jenkinsServersConfig,
  [DataSourceType.K8S_CLUSTERS]: k8sClustersConfig,
  [DataSourceType.GIT_REPOSITORIES]: gitRepositoriesConfig,
  [DataSourceType.DOCKER_REGISTRIES]: dockerRegistriesConfig,
  [DataSourceType.NOTIFICATION_CHANNEL_TYPES]: notificationChannelTypesConfig,
  [DataSourceType.NOTIFICATION_CHANNELS]: notificationChannelsConfig,
  [DataSourceType.USERS]: usersConfig,
  [DataSourceType.ROLES]: rolesConfig,
  [DataSourceType.DEPARTMENTS]: departmentsConfig
};

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

/**
 * 检查数据源类型是否已注册
 * @param type 数据源类型
 * @returns 是否已注册
 */
export const hasDataSource = (type: DataSourceType): boolean => {
  return type in DATA_SOURCE_REGISTRY;
};

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

