/**
 * Enums Constants - SSOT (Single Source of Truth)
 *
 * Todos los enums del sistema. Estos se sincronizan automaticamente
 * al frontend usando el script sync-enums.ts
 *
 * @module @shared/constants/enums
 */

// ============================================================================
// AUTH & USERS
// ============================================================================

/**
 * Roles del sistema de construccion
 */
export const ROLES = {
  // Super Admin (Plataforma)
  SUPER_ADMIN: 'super_admin',

  // Tenant Admin
  ADMIN: 'admin',

  // Direccion
  DIRECTOR_GENERAL: 'director_general',
  DIRECTOR_PROYECTOS: 'director_proyectos',
  DIRECTOR_CONSTRUCCION: 'director_construccion',

  // Gerencias
  GERENTE_ADMINISTRATIVO: 'gerente_administrativo',
  GERENTE_OPERACIONES: 'gerente_operaciones',

  // Ingenieria y Control
  INGENIERO_RESIDENTE: 'ingeniero_residente',
  INGENIERO_COSTOS: 'ingeniero_costos',
  CONTROL_OBRA: 'control_obra',
  PLANEADOR: 'planeador',

  // Supervisores
  SUPERVISOR_OBRA: 'supervisor_obra',
  SUPERVISOR_HSE: 'supervisor_hse',
  SUPERVISOR_CALIDAD: 'supervisor_calidad',

  // Compras y Almacen
  COMPRAS: 'compras',
  ALMACENISTA: 'almacenista',

  // RRHH
  RRHH: 'rrhh',
  NOMINA: 'nomina',

  // Finanzas
  CONTADOR: 'contador',
  TESORERO: 'tesorero',

  // Postventa
  POSTVENTA: 'postventa',

  // Externos
  SUBCONTRATISTA: 'subcontratista',
  PROVEEDOR: 'proveedor',
  DERECHOHABIENTE: 'derechohabiente',

  // Solo lectura
  VIEWER: 'viewer',
} as const;

export type Role = typeof ROLES[keyof typeof ROLES];

/**
 * Estados de cuenta de usuario
 */
export const USER_STATUS = {
  ACTIVE: 'active',
  INACTIVE: 'inactive',
  PENDING: 'pending',
  SUSPENDED: 'suspended',
  BLOCKED: 'blocked',
} as const;

export type UserStatus = typeof USER_STATUS[keyof typeof USER_STATUS];

// ============================================================================
// PROYECTOS Y ESTRUCTURA
// ============================================================================

/**
 * Estados de proyecto
 */
export const PROJECT_STATUS = {
  DRAFT: 'draft',
  PLANNING: 'planning',
  BIDDING: 'bidding',
  AWARDED: 'awarded',
  ACTIVE: 'active',
  PAUSED: 'paused',
  COMPLETED: 'completed',
  CANCELLED: 'cancelled',
} as const;

export type ProjectStatus = typeof PROJECT_STATUS[keyof typeof PROJECT_STATUS];

/**
 * Tipos de proyecto
 */
export const PROJECT_TYPE = {
  HORIZONTAL: 'horizontal',    // Casas individuales
  VERTICAL: 'vertical',        // Edificios/Torres
  MIXED: 'mixed',              // Combinado
  INFRASTRUCTURE: 'infrastructure', // Infraestructura
} as const;

export type ProjectType = typeof PROJECT_TYPE[keyof typeof PROJECT_TYPE];

/**
 * Estados de fraccionamiento
 */
export const FRACCIONAMIENTO_STATUS = {
  ACTIVE: 'activo',
  PAUSED: 'pausado',
  COMPLETED: 'completado',
  CANCELLED: 'cancelado',
} as const;

export type FraccionamientoStatus = typeof FRACCIONAMIENTO_STATUS[keyof typeof FRACCIONAMIENTO_STATUS];

/**
 * Estados de lote
 */
export const LOT_STATUS = {
  AVAILABLE: 'disponible',
  RESERVED: 'apartado',
  SOLD: 'vendido',
  IN_CONSTRUCTION: 'en_construccion',
  DELIVERED: 'entregado',
  WARRANTY: 'en_garantia',
} as const;

export type LotStatus = typeof LOT_STATUS[keyof typeof LOT_STATUS];

// ============================================================================
// PRESUPUESTOS Y COSTOS
// ============================================================================

/**
 * Tipos de concepto de obra
 */
export const CONCEPT_TYPE = {
  MATERIAL: 'material',
  LABOR: 'mano_obra',
  EQUIPMENT: 'equipo',
  SUBCONTRACT: 'subcontrato',
  INDIRECT: 'indirecto',
  OVERHEAD: 'overhead',
  UTILITY: 'utilidad',
} as const;

export type ConceptType = typeof CONCEPT_TYPE[keyof typeof CONCEPT_TYPE];

/**
 * Estados de presupuesto
 */
export const BUDGET_STATUS = {
  DRAFT: 'borrador',
  SUBMITTED: 'enviado',
  APPROVED: 'aprobado',
  CONTRACTED: 'contratado',
  CLOSED: 'cerrado',
} as const;

export type BudgetStatus = typeof BUDGET_STATUS[keyof typeof BUDGET_STATUS];

// ============================================================================
// COMPRAS E INVENTARIOS
// ============================================================================

/**
 * Estados de orden de compra
 */
export const PURCHASE_ORDER_STATUS = {
  DRAFT: 'borrador',
  SUBMITTED: 'enviado',
  APPROVED: 'aprobado',
  CONFIRMED: 'confirmado',
  PARTIAL: 'parcial',
  RECEIVED: 'recibido',
  CANCELLED: 'cancelado',
} as const;

export type PurchaseOrderStatus = typeof PURCHASE_ORDER_STATUS[keyof typeof PURCHASE_ORDER_STATUS];

/**
 * Estados de requisicion
 */
export const REQUISITION_STATUS = {
  DRAFT: 'borrador',
  SUBMITTED: 'enviado',
  APPROVED: 'aprobado',
  REJECTED: 'rechazado',
  ORDERED: 'ordenado',
  CLOSED: 'cerrado',
} as const;

export type RequisitionStatus = typeof REQUISITION_STATUS[keyof typeof REQUISITION_STATUS];

/**
 * Tipos de movimiento de inventario
 */
export const STOCK_MOVE_TYPE = {
  INCOMING: 'entrada',
  OUTGOING: 'salida',
  TRANSFER: 'traspaso',
  ADJUSTMENT: 'ajuste',
  RETURN: 'devolucion',
  CONSUMPTION: 'consumo',
} as const;

export type StockMoveType = typeof STOCK_MOVE_TYPE[keyof typeof STOCK_MOVE_TYPE];

// ============================================================================
// ESTIMACIONES
// ============================================================================

/**
 * Estados de estimacion
 */
export const ESTIMATION_STATUS = {
  DRAFT: 'borrador',
  IN_REVIEW: 'en_revision',
  SUBMITTED: 'enviado',
  CLIENT_REVIEW: 'revision_cliente',
  APPROVED: 'aprobado',
  REJECTED: 'rechazado',
  PAID: 'pagado',
  CANCELLED: 'cancelado',
} as const;

export type EstimationStatus = typeof ESTIMATION_STATUS[keyof typeof ESTIMATION_STATUS];

/**
 * Tipos de retencion
 */
export const RETENTION_TYPE = {
  WARRANTY: 'garantia',
  ADVANCE_AMORTIZATION: 'amortizacion_anticipo',
  IMSS: 'imss',
  ISR: 'isr',
  OTHER: 'otro',
} as const;

export type RetentionType = typeof RETENTION_TYPE[keyof typeof RETENTION_TYPE];

// ============================================================================
// HSE (Health, Safety & Environment)
// ============================================================================

/**
 * Severidad de incidente
 */
export const INCIDENT_SEVERITY = {
  LOW: 'bajo',
  MEDIUM: 'medio',
  HIGH: 'alto',
  CRITICAL: 'critico',
  FATAL: 'fatal',
} as const;

export type IncidentSeverity = typeof INCIDENT_SEVERITY[keyof typeof INCIDENT_SEVERITY];

/**
 * Tipos de incidente
 */
export const INCIDENT_TYPE = {
  ACCIDENT: 'accidente',
  NEAR_MISS: 'casi_accidente',
  UNSAFE_CONDITION: 'condicion_insegura',
  UNSAFE_ACT: 'acto_inseguro',
  FIRST_AID: 'primeros_auxilios',
  ENVIRONMENTAL: 'ambiental',
} as const;

export type IncidentType = typeof INCIDENT_TYPE[keyof typeof INCIDENT_TYPE];

/**
 * Estados de incidente
 */
export const INCIDENT_STATUS = {
  REPORTED: 'reportado',
  UNDER_INVESTIGATION: 'en_investigacion',
  PENDING_ACTIONS: 'pendiente_acciones',
  ACTIONS_IN_PROGRESS: 'acciones_en_progreso',
  CLOSED: 'cerrado',
} as const;

export type IncidentStatus = typeof INCIDENT_STATUS[keyof typeof INCIDENT_STATUS];

/**
 * Tipos de capacitacion
 */
export const TRAINING_TYPE = {
  INDUCTION: 'induccion',
  SAFETY: 'seguridad',
  TECHNICAL: 'tecnico',
  REGULATORY: 'normativo',
  REFRESHER: 'actualizacion',
  CERTIFICATION: 'certificacion',
} as const;

export type TrainingType = typeof TRAINING_TYPE[keyof typeof TRAINING_TYPE];

/**
 * Tipos de permiso de trabajo
 */
export const WORK_PERMIT_TYPE = {
  HOT_WORK: 'trabajo_caliente',
  CONFINED_SPACE: 'espacio_confinado',
  HEIGHT_WORK: 'trabajo_altura',
  ELECTRICAL: 'electrico',
  EXCAVATION: 'excavacion',
  LIFTING: 'izaje',
} as const;

export type WorkPermitType = typeof WORK_PERMIT_TYPE[keyof typeof WORK_PERMIT_TYPE];

// ============================================================================
// RRHH
// ============================================================================

/**
 * Tipos de empleado
 */
export const EMPLOYEE_TYPE = {
  PERMANENT: 'planta',
  TEMPORARY: 'temporal',
  CONTRACTOR: 'contratista',
  INTERN: 'practicante',
} as const;

export type EmployeeType = typeof EMPLOYEE_TYPE[keyof typeof EMPLOYEE_TYPE];

/**
 * Tipos de asistencia
 */
export const ATTENDANCE_TYPE = {
  CHECK_IN: 'entrada',
  CHECK_OUT: 'salida',
  BREAK_START: 'inicio_descanso',
  BREAK_END: 'fin_descanso',
} as const;

export type AttendanceType = typeof ATTENDANCE_TYPE[keyof typeof ATTENDANCE_TYPE];

/**
 * Metodos de validacion de asistencia
 */
export const ATTENDANCE_VALIDATION = {
  GPS: 'gps',
  BIOMETRIC: 'biometrico',
  QR: 'qr',
  MANUAL: 'manual',
  NFC: 'nfc',
} as const;

export type AttendanceValidation = typeof ATTENDANCE_VALIDATION[keyof typeof ATTENDANCE_VALIDATION];

// ============================================================================
// INFONAVIT
// ============================================================================

/**
 * Estados de asignacion INFONAVIT
 */
export const INFONAVIT_ASSIGNMENT_STATUS = {
  AVAILABLE: 'disponible',
  IN_PROCESS: 'en_proceso',
  ASSIGNED: 'asignado',
  DOCUMENTED: 'documentado',
  REGISTERED: 'registrado',
  DELIVERED: 'entregado',
} as const;

export type InfonavitAssignmentStatus = typeof INFONAVIT_ASSIGNMENT_STATUS[keyof typeof INFONAVIT_ASSIGNMENT_STATUS];

/**
 * Programas INFONAVIT
 */
export const INFONAVIT_PROGRAM = {
  TRADICIONAL: 'tradicional',
  COFINAVIT: 'cofinavit',
  APOYO_INFONAVIT: 'apoyo_infonavit',
  UNAMOS_CREDITOS: 'unamos_creditos',
  MEJORAVIT: 'mejoravit',
} as const;

export type InfonavitProgram = typeof INFONAVIT_PROGRAM[keyof typeof INFONAVIT_PROGRAM];

// ============================================================================
// CALIDAD Y POSTVENTA
// ============================================================================

/**
 * Estados de ticket postventa
 */
export const TICKET_STATUS = {
  OPEN: 'abierto',
  IN_PROGRESS: 'en_proceso',
  PENDING_CUSTOMER: 'pendiente_cliente',
  PENDING_PARTS: 'pendiente_refacciones',
  RESOLVED: 'resuelto',
  CLOSED: 'cerrado',
} as const;

export type TicketStatus = typeof TICKET_STATUS[keyof typeof TICKET_STATUS];

/**
 * Prioridad de ticket
 */
export const TICKET_PRIORITY = {
  LOW: 'baja',
  MEDIUM: 'media',
  HIGH: 'alta',
  URGENT: 'urgente',
} as const;

export type TicketPriority = typeof TICKET_PRIORITY[keyof typeof TICKET_PRIORITY];

// ============================================================================
// DOCUMENTOS
// ============================================================================

/**
 * Estados de documento
 */
export const DOCUMENT_STATUS = {
  DRAFT: 'borrador',
  PENDING_REVIEW: 'pendiente_revision',
  APPROVED: 'aprobado',
  REJECTED: 'rechazado',
  OBSOLETE: 'obsoleto',
} as const;

export type DocumentStatus = typeof DOCUMENT_STATUS[keyof typeof DOCUMENT_STATUS];

/**
 * Tipos de documento
 */
export const DOCUMENT_TYPE = {
  PLAN: 'plano',
  CONTRACT: 'contrato',
  PERMIT: 'permiso',
  CERTIFICATE: 'certificado',
  REPORT: 'reporte',
  PHOTO: 'fotografia',
  OTHER: 'otro',
} as const;

export type DocumentType = typeof DOCUMENT_TYPE[keyof typeof DOCUMENT_TYPE];

// ============================================================================
// WORKFLOW
// ============================================================================

/**
 * Acciones de workflow
 */
export const WORKFLOW_ACTION = {
  SUBMIT: 'submit',
  APPROVE: 'approve',
  REJECT: 'reject',
  RETURN: 'return',
  CANCEL: 'cancel',
  REOPEN: 'reopen',
} as const;

export type WorkflowAction = typeof WORKFLOW_ACTION[keyof typeof WORKFLOW_ACTION];

// ============================================================================
// AUDIT
// ============================================================================

/**
 * Tipos de accion de auditoria
 */
export const AUDIT_ACTION = {
  CREATE: 'create',
  UPDATE: 'update',
  DELETE: 'delete',
  VIEW: 'view',
  EXPORT: 'export',
  LOGIN: 'login',
  LOGOUT: 'logout',
} as const;

export type AuditAction = typeof AUDIT_ACTION[keyof typeof AUDIT_ACTION];
