/**
 * Unified Registry Generator
 *
 * Generates index.ts (the main registry entry point)
 *
 * @module core/scripts/build/registry/generators/unified-registry
 */

/**
 * Generate the unified registry index file
 *
 * @param {Array} plugins - Discovered plugins
 * @param {Array} entities - Discovered entities
 * @param {Array} themes - Discovered themes
 * @param {Array} templates - Discovered templates
 * @param {Array} middlewares - Discovered middlewares
 * @param {object} config - Configuration object from getConfig()
 * @returns {string} Generated TypeScript content
 */
export function generateUnifiedRegistry(plugins, entities, themes, templates, middlewares, config) {
  return `/**
 * Auto-generated Unified Registry
 *
 * Generated at: ${new Date().toISOString()}
 * Total contents: ${plugins.length + entities.length + themes.length + templates.length}
 *
 * DO NOT EDIT - This file is auto-generated by scripts/build-registry.mjs
 */

export * from './plugin-registry'
export * from './entity-registry'
export * from './theme-registry'
export * from './template-registry'
export * from './middleware-registry'
export * from './scope-registry'
export * from './namespace-registry'

import { PLUGIN_REGISTRY, PLUGIN_METADATA, type PluginName } from './plugin-registry'
import { ENTITY_REGISTRY, ENTITY_METADATA, type EntityName } from './entity-registry'
import { THEME_REGISTRY, THEME_METADATA, type ThemeName } from './theme-registry'
import { TEMPLATE_REGISTRY, TEMPLATE_METADATA, type TemplatePath } from './template-registry'
import { MIDDLEWARE_REGISTRY, MIDDLEWARE_METADATA } from './middleware-registry'
import { SCOPE_CONFIG, API_CONFIG } from './scope-registry'
import { NAMESPACE_CONFIG } from './namespace-registry'

/**
 * Unified Contents Registry - Ultra-fast access to all content types
 */
export const CONTENTS_REGISTRY = {
  plugins: PLUGIN_REGISTRY,
  entities: ENTITY_REGISTRY,
  themes: THEME_REGISTRY,
  templates: TEMPLATE_REGISTRY,
  middlewares: MIDDLEWARE_REGISTRY,
  scopes: SCOPE_CONFIG,
  api: API_CONFIG,
  namespaces: NAMESPACE_CONFIG
}

/**
 * Unified metadata for all content types
 */
export const CONTENTS_METADATA = {
  plugins: PLUGIN_METADATA,
  entities: ENTITY_METADATA,
  themes: THEME_METADATA,
  templates: TEMPLATE_METADATA,
  middlewares: MIDDLEWARE_METADATA,
  totals: {
    plugins: ${plugins.length},
    entities: ${entities.length},
    themes: ${themes.length},
    templates: ${templates.length},
    middlewares: ${middlewares.length},
    total: ${plugins.length + entities.length + themes.length + templates.length + middlewares.length}
  },
  generatedAt: '${new Date().toISOString()}'
}

/**
 * Unified type exports
 */
export type { PluginName, EntityName, ThemeName, TemplatePath }
`
}
