/**
 * Database Constants - Single Source of Truth
 *
 * @description Centraliza todos los nombres de schemas y tablas del sistema.
 * Las entities deben usar estas constantes en lugar de strings hardcodeados.
 *
 * @usage
 * ```typescript
 * import { DB_SCHEMAS, DB_TABLES } from '@shared/constants';
 *
 * @Entity({ schema: DB_SCHEMAS.AUTH, name: DB_TABLES.AUTH.USERS })
 * export class User { ... }
 * ```
 *
 * @migration Para migrar entities existentes:
 * - Buscar: `{ schema: 'auth'` → Reemplazar: `{ schema: DB_SCHEMAS.AUTH`
 * - Buscar: `'users'` en @Entity → Reemplazar: `DB_TABLES.AUTH.USERS`
 */

/**
 * Schema names del sistema
 */
export const DB_SCHEMAS = {
  /** Schema de autenticación y usuarios */
  AUTH: 'auth',
  /** Schema de CRM (clientes, marcas, productos) */
  CRM: 'crm',
  /** Schema de assets/medios digitales */
  ASSETS: 'assets',
  /** Schema de proyectos y contenido */
  PROJECTS: 'projects',
  /** Schema de tenants/multi-tenancy */
  TENANTS: 'tenants',
} as const;

/**
 * Table names por schema
 */
export const DB_TABLES = {
  AUTH: {
    USERS: 'users',
    SESSIONS: 'sessions',
    PASSWORD_RESET_TOKENS: 'password_reset_tokens',
  },
  CRM: {
    CLIENTS: 'clients',
    BRANDS: 'brands',
    PRODUCTS: 'products',
  },
  ASSETS: {
    ASSETS: 'assets',
    ASSET_FOLDERS: 'asset_folders',
    ASSET_VERSIONS: 'asset_versions',
    ASSET_TAGS: 'asset_tags',
  },
  PROJECTS: {
    PROJECTS: 'projects',
    CONTENT_PIECES: 'content_pieces',
    CONTENT_VERSIONS: 'content_versions',
    PROJECT_MEMBERS: 'project_members',
  },
  TENANTS: {
    TENANTS: 'tenants',
    TENANT_PLANS: 'tenant_plans',
    TENANT_SETTINGS: 'tenant_settings',
  },
} as const;

/**
 * Type helpers para intellisense
 */
export type SchemaName = typeof DB_SCHEMAS[keyof typeof DB_SCHEMAS];
export type AuthTableName = typeof DB_TABLES.AUTH[keyof typeof DB_TABLES.AUTH];
export type CrmTableName = typeof DB_TABLES.CRM[keyof typeof DB_TABLES.CRM];
export type AssetsTableName = typeof DB_TABLES.ASSETS[keyof typeof DB_TABLES.ASSETS];
export type ProjectsTableName = typeof DB_TABLES.PROJECTS[keyof typeof DB_TABLES.PROJECTS];
export type TenantsTableName = typeof DB_TABLES.TENANTS[keyof typeof DB_TABLES.TENANTS];
