// ============ 代理与Web ============
import { nginxSchema, generateNginxConf } from './nginx'
import { apacheSchema, generateApacheConf } from './apache'
import { tomcatSchema, generateTomcatServerXml } from './tomcat'

// ============ 缓存 ============
import { redisSchema, generateRedisConf } from './redis'

// ============ 数据库 ============
import { mysqlSchema, generateMysqlConf } from './mysql'
import { mongodbSchema, generateMongodbConf } from './mongodb'
import { postgresqlSchema, generatePostgresqlConf } from './postgresql'
import { oracleSchema, generateOracleConf } from './oracle'

// ============ 搜索引擎 ============
import { elasticsearchSchema, generateElasticsearchYml } from './elasticsearch'

// ============ 消息队列 ============
import { rocketmqSchema, generateRocketmqConf } from './rocketmq'
import { kafkaSchema, generateKafkaProperties } from './kafka'

// ============ K8S 工作负载 ============
import { k8sPodSchema, generateK8sPodYaml } from './k8s-pod'
import { k8sDeploymentSchema, generateK8sDeploymentYaml } from './k8s-deployment'
import { k8sStatefulSetSchema, generateK8sStatefulSetYaml } from './k8s-statefulset'
import { k8sDaemonSetSchema, generateK8sDaemonSetYaml } from './k8s-daemonset'
import { k8sJobSchema, generateK8sJobYaml } from './k8s-job'
import { k8sCronJobSchema, generateK8sCronJobYaml } from './k8s-cronjob'

// ============ K8S 服务发现 ============
import { k8sServiceSchema, generateK8sServiceYaml } from './k8s-service'
import { k8sIngressSchema, generateK8sIngressYaml } from './k8s-ingress'

// ============ K8S 存储 ============
import { k8sPvSchema, generateK8sPvYaml } from './k8s-pv'
import { k8sPvcSchema, generateK8sPvcYaml } from './k8s-pvc'
import { k8sStorageClassSchema, generateK8sStorageClassYaml } from './k8s-storageclass'

// ============ K8S 配置与密钥 ============
import { k8sConfigMapSchema, generateK8sConfigMapYaml } from './k8s-configmap'
import { k8sSecretSchema, generateK8sSecretYaml } from './k8s-secret'

// ============ K8S 安全与权限 ============
import { k8sServiceAccountSchema, generateK8sServiceAccountYaml } from './k8s-serviceaccount'
import { k8sRoleSchema, generateK8sRoleYaml } from './k8s-role'
import { k8sClusterRoleSchema, generateK8sClusterRoleYaml } from './k8s-clusterrole'
import { k8sRoleBindingSchema, generateK8sRoleBindingYaml } from './k8s-rolebinding'
import { k8sClusterRoleBindingSchema, generateK8sClusterRoleBindingYaml } from './k8s-clusterrolebinding'
import { k8sNetworkPolicySchema, generateK8sNetworkPolicyYaml } from './k8s-networkpolicy'

// ============ K8S 集群管理 ============
import { k8sNamespaceSchema, generateK8sNamespaceYaml } from './k8s-namespace'

// ============ 服务治理 ============
import { nacosSchema, generateNacosProperties } from './nacos'

// ============ 分布式协调 ============
import { zookeeperSchema, generateZookeeperCfg } from './zookeeper'
import { etcdSchema, generateEtcdYml } from './etcd'

// ============ 容器化 ============
import { dockerSchema, generateDockerDaemonJson } from './docker'
import { dockerComposeSchema, generateDockerComposeYml } from './docker-compose'

// ============ 日志监控 ============
import { logstashSchema, generateLogstashConf } from './logstash'
import { kibanaSchema, generateKibanaYml } from './kibana'
import { prometheusSchema, generatePrometheusYml } from './prometheus'
import { grafanaSchema, generateGrafanaIni } from './grafana'
import { zabbixSchema, generateZabbixConf } from './zabbix'
import { syslogSchema, generateSyslogConf } from './syslog'

// ============ 自动化运维 ============
import { ansibleSchema, generateAnsibleCfg } from './ansible'
import { ansiblePlaybookSchema, generateAnsiblePlaybookYaml } from './ansible-playbook'

// ============ CI/CD ============
import { gitlabSchema, generateGitlabRb } from './gitlab'
import { jenkinsSchema, generateJenkinsYaml } from './jenkins'

// ============ 高可用 ============
import { keepalivedSchema, generateKeepalivedConf } from './keepalived'
import { haproxySchema, generateHaproxyCfg } from './haproxy'
import { lvsSchema, generateLvsConf } from './lvs'

// ============ 系统服务 ============
import { ntpSchema, generateNtpConf } from './ntp'
import { dhcpSchema, generateDhcpConf } from './dhcp'
import { bindSchema, generateBindConf } from './bind'
import { nfsSchema, generateNfsExports } from './nfs'
import { sambaSchema, generateSambaConf } from './samba'
import { rsyncSchema, generateRsyncConf } from './rsync'
import { sersyncSchema, generateSersyncXml } from './sersync'
import { vsftpdSchema, generateVsftpdConf } from './vsftpd'
import { subversionSchema, generateSubversionConf } from './subversion'

// ============ 数据库中间件 ============
import { mycatSchema, generateMycatServerXml } from './mycat'

// ============================================================
// Schema Registry
// ============================================================

export const schemas = {
  // 代理与Web
  nginx: nginxSchema,
  apache: apacheSchema,
  tomcat: tomcatSchema,
  // 缓存
  redis: redisSchema,
  // 数据库
  mysql: mysqlSchema,
  mongodb: mongodbSchema,
  postgresql: postgresqlSchema,
  oracle: oracleSchema,
  // 搜索引擎
  elasticsearch: elasticsearchSchema,
  // 消息队列
  rocketmq: rocketmqSchema,
  kafka: kafkaSchema,
  // K8S 工作负载
  'k8s-pod': k8sPodSchema,
  'k8s-deployment': k8sDeploymentSchema,
  'k8s-statefulset': k8sStatefulSetSchema,
  'k8s-daemonset': k8sDaemonSetSchema,
  'k8s-job': k8sJobSchema,
  'k8s-cronjob': k8sCronJobSchema,
  // K8S 服务发现
  'k8s-service': k8sServiceSchema,
  'k8s-ingress': k8sIngressSchema,
  // K8S 存储
  'k8s-pv': k8sPvSchema,
  'k8s-pvc': k8sPvcSchema,
  'k8s-storageclass': k8sStorageClassSchema,
  // K8S 配置与密钥
  'k8s-configmap': k8sConfigMapSchema,
  'k8s-secret': k8sSecretSchema,
  // K8S 安全与权限
  'k8s-serviceaccount': k8sServiceAccountSchema,
  'k8s-role': k8sRoleSchema,
  'k8s-clusterrole': k8sClusterRoleSchema,
  'k8s-rolebinding': k8sRoleBindingSchema,
  'k8s-clusterrolebinding': k8sClusterRoleBindingSchema,
  'k8s-networkpolicy': k8sNetworkPolicySchema,
  // K8S 集群管理
  'k8s-namespace': k8sNamespaceSchema,
  // 服务治理
  nacos: nacosSchema,
  // 分布式协调
  zookeeper: zookeeperSchema,
  etcd: etcdSchema,
  // 容器化
  docker: dockerSchema,
  'docker-compose': dockerComposeSchema,
  // 日志监控
  logstash: logstashSchema,
  kibana: kibanaSchema,
  prometheus: prometheusSchema,
  grafana: grafanaSchema,
  zabbix: zabbixSchema,
  syslog: syslogSchema,
  // 自动化运维
  ansible: ansibleSchema,
  'ansible-playbook': ansiblePlaybookSchema,
  // CI/CD
  gitlab: gitlabSchema,
  jenkins: jenkinsSchema,
  // 高可用
  keepalived: keepalivedSchema,
  haproxy: haproxySchema,
  lvs: lvsSchema,
  // 系统服务
  ntp: ntpSchema,
  dhcp: dhcpSchema,
  bind: bindSchema,
  nfs: nfsSchema,
  samba: sambaSchema,
  rsync: rsyncSchema,
  sersync: sersyncSchema,
  vsftpd: vsftpdSchema,
  subversion: subversionSchema,
  // 数据库中间件
  mycat: mycatSchema,
}

// ============================================================
// Generator Registry
// ============================================================

export const generators = {
  nginx: generateNginxConf,
  apache: generateApacheConf,
  tomcat: generateTomcatServerXml,
  redis: generateRedisConf,
  mysql: generateMysqlConf,
  mongodb: generateMongodbConf,
  postgresql: generatePostgresqlConf,
  oracle: generateOracleConf,
  elasticsearch: generateElasticsearchYml,
  rocketmq: generateRocketmqConf,
  kafka: generateKafkaProperties,
  'k8s-pod': generateK8sPodYaml,
  'k8s-deployment': generateK8sDeploymentYaml,
  'k8s-statefulset': generateK8sStatefulSetYaml,
  'k8s-daemonset': generateK8sDaemonSetYaml,
  'k8s-job': generateK8sJobYaml,
  'k8s-cronjob': generateK8sCronJobYaml,
  'k8s-service': generateK8sServiceYaml,
  'k8s-ingress': generateK8sIngressYaml,
  'k8s-pv': generateK8sPvYaml,
  'k8s-pvc': generateK8sPvcYaml,
  'k8s-storageclass': generateK8sStorageClassYaml,
  'k8s-configmap': generateK8sConfigMapYaml,
  'k8s-secret': generateK8sSecretYaml,
  'k8s-serviceaccount': generateK8sServiceAccountYaml,
  'k8s-role': generateK8sRoleYaml,
  'k8s-clusterrole': generateK8sClusterRoleYaml,
  'k8s-rolebinding': generateK8sRoleBindingYaml,
  'k8s-clusterrolebinding': generateK8sClusterRoleBindingYaml,
  'k8s-networkpolicy': generateK8sNetworkPolicyYaml,
  'k8s-namespace': generateK8sNamespaceYaml,
  nacos: generateNacosProperties,
  zookeeper: generateZookeeperCfg,
  etcd: generateEtcdYml,
  docker: generateDockerDaemonJson,
  'docker-compose': generateDockerComposeYml,
  logstash: generateLogstashConf,
  kibana: generateKibanaYml,
  prometheus: generatePrometheusYml,
  grafana: generateGrafanaIni,
  zabbix: generateZabbixConf,
  syslog: generateSyslogConf,
  ansible: generateAnsibleCfg,
  'ansible-playbook': generateAnsiblePlaybookYaml,
  // CI/CD
  gitlab: generateGitlabRb,
  jenkins: generateJenkinsYaml,
  // 高可用
  keepalived: generateKeepalivedConf,
  haproxy: generateHaproxyCfg,
  lvs: generateLvsConf,
  // 系统服务
  ntp: generateNtpConf,
  dhcp: generateDhcpConf,
  bind: generateBindConf,
  nfs: generateNfsExports,
  samba: generateSambaConf,
  rsync: generateRsyncConf,
  sersync: generateSersyncXml,
  vsftpd: generateVsftpdConf,
  subversion: generateSubversionConf,
  // 数据库中间件
  mycat: generateMycatServerXml,
}

// ============================================================
// Sidebar Categories
// ============================================================

export const categories = [
  {
    name: '代理与Web',
    icon: 'Monitor',
    items: ['nginx', 'apache', 'tomcat'],
  },
  {
    name: '缓存',
    icon: 'Coin',
    items: ['redis'],
  },
  {
    name: '数据库',
    icon: 'Coin',
    items: ['mysql', 'postgresql', 'mongodb', 'oracle'],
  },
  {
    name: '搜索引擎',
    icon: 'Search',
    items: ['elasticsearch'],
  },
  {
    name: '消息队列',
    icon: 'ChatDotRound',
    items: ['rocketmq', 'kafka'],
  },
  {
    name: 'K8S 工作负载',
    icon: 'Box',
    items: ['k8s-pod', 'k8s-deployment', 'k8s-statefulset', 'k8s-daemonset', 'k8s-job', 'k8s-cronjob'],
  },
  {
    name: 'K8S 服务发现',
    icon: 'Connection',
    items: ['k8s-service', 'k8s-ingress'],
  },
  {
    name: 'K8S 存储',
    icon: 'Files',
    items: ['k8s-pv', 'k8s-pvc', 'k8s-storageclass'],
  },
  {
    name: 'K8S 配置与密钥',
    icon: 'Document',
    items: ['k8s-configmap', 'k8s-secret'],
  },
  {
    name: 'K8S 安全与权限',
    icon: 'Lock',
    items: ['k8s-serviceaccount', 'k8s-role', 'k8s-clusterrole', 'k8s-rolebinding', 'k8s-clusterrolebinding', 'k8s-networkpolicy'],
  },
  {
    name: 'K8S 集群管理',
    icon: 'Grid',
    items: ['k8s-namespace'],
  },
  {
    name: '服务治理',
    icon: 'Connection',
    items: ['nacos'],
  },
  {
    name: '分布式协调',
    icon: 'Connection',
    items: ['zookeeper', 'etcd'],
  },
  {
    name: '容器化',
    icon: 'Box',
    items: ['docker', 'docker-compose'],
  },
  {
    name: '日志监控',
    icon: 'TrendCharts',
    items: ['logstash', 'kibana', 'prometheus', 'grafana', 'zabbix', 'syslog'],
  },
  {
    name: '自动化运维',
    icon: 'Files',
    items: ['ansible', 'ansible-playbook'],
  },
  {
    name: 'CI/CD',
    icon: 'Files',
    items: ['gitlab', 'jenkins'],
  },
  {
    name: '高可用',
    icon: 'Connection',
    items: ['keepalived', 'haproxy', 'lvs'],
  },
  {
    name: '系统服务',
    icon: 'Setting',
    items: ['ntp', 'dhcp', 'bind', 'nfs', 'samba', 'rsync', 'sersync', 'vsftpd', 'subversion'],
  },
  {
    name: '数据库中间件',
    icon: 'Coin',
    items: ['mycat'],
  },
]

// ============================================================
// Utility Functions
// ============================================================

export function getDefaultValues(schema) {
  const defaults = {}
  for (const group of schema.groups) {
    for (const field of group.fields) {
      defaults[field.key] = field.default
    }
  }
  return defaults
}

export function getLanguage(format) {
  const map = {
    conf: 'ini',
    cnf: 'ini',
    cfg: 'ini',
    ora: 'ini',
    rb: 'ruby',
    yml: 'yaml',
    yaml: 'yaml',
    json: 'json',
    toml: 'toml',
    properties: 'properties',
    ini: 'ini',
    xml: 'xml',
  }
  return map[format] || 'plaintext'
}
