import { VOCAB } from '@/lib/white-label/constants';

/**
 * ${VOCAB.factory} Generation Options
 * Language, Database, and Expert Mode type definitions
 */

export type TargetLanguage = 'typescript-react' | 'csharp' | 'python-fastapi' | 'go' | 'java-spring';
export type TargetDatabase = 'postgresql' | 'mssql' | 'mysql' | 'sqlite';

export interface LanguageOption {
  id: TargetLanguage;
  label: string;
  shortLabel: string;
  icon: string;  // emoji fallback
  description: string;
  fileExtensions: string[];
  framework: string;
}

export interface DatabaseOption {
  id: TargetDatabase;
  label: string;
  shortLabel: string;
  icon: string;
  description: string;
  ormDefault: string;
}

export const LANGUAGE_OPTIONS: LanguageOption[] = [
  {
    id: 'typescript-react',
    label: 'TypeScript + React',
    shortLabel: 'React/TS',
    icon: '⚛️',
    description: 'Next.js 14 with React and TypeScript',
    fileExtensions: ['.tsx', '.ts'],
    framework: 'Next.js 14',
  },
  {
    id: 'csharp',
    label: 'C# + .NET',
    shortLabel: 'C#/.NET',
    icon: '🟣',
    description: 'ASP.NET Core with Entity Framework',
    fileExtensions: ['.cs', '.csproj'],
    framework: 'ASP.NET Core 8',
  },
  {
    id: 'python-fastapi',
    label: 'Python + FastAPI',
    shortLabel: 'Python',
    icon: '🐍',
    description: 'FastAPI with SQLAlchemy ORM',
    fileExtensions: ['.py'],
    framework: 'FastAPI',
  },
  {
    id: 'go',
    label: 'Go',
    shortLabel: 'Go',
    icon: '🔵',
    description: 'Go with Gin framework and GORM',
    fileExtensions: ['.go'],
    framework: 'Gin + GORM',
  },
  {
    id: 'java-spring',
    label: 'Java + Spring Boot',
    shortLabel: 'Java',
    icon: '☕',
    description: 'Spring Boot with JPA/Hibernate',
    fileExtensions: ['.java'],
    framework: 'Spring Boot 3',
  },
];

export const DATABASE_OPTIONS: DatabaseOption[] = [
  {
    id: 'postgresql',
    label: 'PostgreSQL',
    shortLabel: 'Postgres',
    icon: '🐘',
    description: 'Full-featured relational DB (default)',
    ormDefault: 'Prisma',
  },
  {
    id: 'mssql',
    label: 'Microsoft SQL Server',
    shortLabel: 'MSSQL',
    icon: '🟦',
    description: 'Enterprise-grade SQL Server',
    ormDefault: 'Entity Framework',
  },
  {
    id: 'mysql',
    label: 'MySQL',
    shortLabel: 'MySQL',
    icon: '🐬',
    description: 'Popular open-source database',
    ormDefault: 'Prisma',
  },
  {
    id: 'sqlite',
    label: 'SQLite',
    shortLabel: 'SQLite',
    icon: '📦',
    description: 'Lightweight file-based database',
    ormDefault: 'Prisma',
  },
];

/** Expert Mode - Editable pre-generation specification */
export interface ExpertModeSpec {
  entities: ExpertEntity[];
  endpoints: ExpertEndpoint[];
  namingConventions: NamingConventions;
  summary: string;
}

export interface ExpertEntity {
  name: string;
  description: string;
  fields: ExpertField[];
  relations: ExpertRelation[];
}

export interface ExpertField {
  name: string;
  type: string;
  required: boolean;
  description: string;
}

export interface ExpertRelation {
  name: string;
  type: string;
  target: string;
  description: string;
}

export interface ExpertEndpoint {
  path: string;
  method: string;
  description: string;
  businessLogic: string[];
}

export interface NamingConventions {
  modelCase: 'PascalCase' | 'camelCase' | 'snake_case';
  fieldCase: 'camelCase' | 'snake_case' | 'PascalCase';
  endpointCase: 'kebab-case' | 'snake_case' | 'camelCase';
  fileNaming: 'kebab-case' | 'PascalCase' | 'snake_case';
}

export interface GenerationOptions {
  language: TargetLanguage;
  database: TargetDatabase;
  expertMode: boolean;
}

export function getLanguageOption(id: TargetLanguage): LanguageOption {
  return LANGUAGE_OPTIONS.find(l => l.id === id) || LANGUAGE_OPTIONS[0];
}

export function getDatabaseOption(id: TargetDatabase): DatabaseOption {
  return DATABASE_OPTIONS.find(d => d.id === id) || DATABASE_OPTIONS[0];
}
