import type { DomainTemplate } from './types.js'
import {
  getAllTemplates,
  getTemplate,
  getTemplatesByTag,
  getTemplatesByCategory,
  searchTemplates,
  getTemplateStats,
} from './meta/index.js'

/**
 * Registry of all available domain templates with their metadata.
 * This provides a central location for UI components to discover and present templates.
 *
 * The templates are pre-processed at build time using the generate-template-metadata.js script
 * to avoid loading and processing all templates on the client side.
 */
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class TemplateRegistry {
  /**
   * Gets all available templates
   */
  static getAllTemplates(): DomainTemplate[] {
    return getAllTemplates()
  }

  /**
   * Gets a template by its ID
   */
  static getTemplate(id: string): DomainTemplate | undefined {
    return getTemplate(id)
  }

  /**
   * Gets templates filtered by tags
   */
  static getTemplatesByTag(tag: string): DomainTemplate[] {
    return getTemplatesByTag(tag)
  }

  /**
   * Gets templates filtered by category (based on tags)
   */
  static getTemplatesByCategory(category: 'business' | 'content' | 'social' | 'technical'): DomainTemplate[] {
    return getTemplatesByCategory(category)
  }

  /**
   * Gets templates filtered by industry vertical
   */
  static getTemplatesByVertical(vertical: string): DomainTemplate[] {
    // This would need to be implemented in the meta/index.js
    return getAllTemplates().filter((template) =>
      template.tags?.some((tag) => tag.toLowerCase().includes(vertical.toLowerCase()))
    )
  }

  /**
   * Gets all available industry verticals
   */
  static getIndustryVerticals(): {
    id: string
    name: string
    description: string
    subcategories: string[]
    templateCount: number
  }[] {
    return [
      {
        id: 'business-services',
        name: 'Business Services',
        description: 'E-commerce, Financial Services, Legal Services',
        subcategories: ['E-commerce', 'Financial Services', 'Legal Services'],
        templateCount: 4,
      },
      {
        id: 'healthcare-life-sciences',
        name: 'Healthcare & Life Sciences',
        description: 'Healthcare, Pharmaceutical, Research',
        subcategories: ['Healthcare', 'Pharmaceutical', 'Research'],
        templateCount: 1,
      },
      {
        id: 'education-training',
        name: 'Education & Training',
        description: 'Education, Corporate Training, Certification',
        subcategories: ['Education', 'Corporate Training', 'Certification'],
        templateCount: 1,
      },
      {
        id: 'real-estate-construction',
        name: 'Real Estate & Construction',
        description: 'Real Estate, Construction, Property Management',
        subcategories: ['Real Estate', 'Construction', 'Property Management'],
        templateCount: 1,
      },
      {
        id: 'manufacturing-logistics',
        name: 'Manufacturing & Logistics',
        description: 'Manufacturing, Supply Chain, Distribution',
        subcategories: ['Manufacturing', 'Supply Chain', 'Distribution'],
        templateCount: 1,
      },
      {
        id: 'technology-media',
        name: 'Technology & Media',
        description: 'Gaming, IoT, Content Management, Social Media',
        subcategories: ['Gaming', 'IoT', 'Content Management', 'Social Media'],
        templateCount: 3,
      },
      {
        id: 'public-sector',
        name: 'Public Sector',
        description: 'Government, Non-Profit, Healthcare',
        subcategories: ['Government', 'Non-Profit', 'Healthcare'],
        templateCount: 1,
      },
    ]
  }

  /**
   * Searches templates by name or description
   */
  static searchTemplates(query: string): DomainTemplate[] {
    return searchTemplates(query)
  }

  /**
   * Gets template statistics for analytics
   */
  static getTemplateStats(): {
    totalTemplates: number
    totalEntities: number
    totalProperties: number
    totalAssociations: number
    categoryCounts: Record<string, number>
  } {
    return getTemplateStats()
  }
}
