export const STRATEGIC_SECTION_KEYS = ["technical", "experience", "organization", "publicProcurement"] as const;

export type StrategicSectionKey = (typeof STRATEGIC_SECTION_KEYS)[number];

export type StrategicDiagnosticData = {
  technical: {
    productsServicesDescription: string;
    installedCapacityEmployees: string;
    equipment: string;
    infrastructure: string;
    coverageRegions: string[];
    responseTimes: string;
    certifications: string[];
  };
  experience: {
    hasGovernmentSectorExperience: boolean;
    hasPrivateSectorExperience: boolean;
    sectorsServed: string[];
    contractTypes: string[];
    approximateContractAmounts: string;
    successCases: string;
  };
  organization: {
    structureType: string;
    roles: {
      generalManagement: boolean;
      legal: boolean;
      finance: boolean;
      operations: boolean;
    };
    compliance: {
      fiscal: boolean;
      labor: boolean;
      documentedProcesses: boolean;
    };
  };
  publicProcurement: {
    processKnowledgeLevel: number;
    hasTenderBasesExperience: boolean;
    technicalProposalCapacityLevel: number;
    administrativeRequirementsCapacityLevel: number;
    hasBiddingTeam: boolean;
    biddingTeamAvailability: string;
  };
};

export type StrategicDiagnosticScores = {
  sectionScores: Record<StrategicSectionKey, number>;
  sectionCompletion: Record<StrategicSectionKey, boolean>;
  completedSections: number;
  totalSections: number;
  overallScore: number;
  strengths: string[];
  gaps: string[];
  risks: string[];
};

export type StrategicEvidenceDocumentView = {
  id: string;
  section: StrategicSectionKey;
  category: string;
  fileName: string;
  filePath: string;
  mimeType: string;
  sizeBytes: number;
  createdAt: string;
};

export type StrategicDiagnosticSnapshot = {
  organizationId: string;
  data: StrategicDiagnosticData;
  scores: StrategicDiagnosticScores;
  evidenceBySection: Record<StrategicSectionKey, StrategicEvidenceDocumentView[]>;
  aiInsights?: StrategicAiInsights | null;
  completedAt: string | null;
};

export type StrategicAiInsights = {
  sectionGaps: {
    sectionKey: StrategicSectionKey;
    gap: string;
    impact: string;
    urgency: "alta" | "media" | "baja";
  }[];
  priorityActions: {
    title: string;
    description: string;
    priority: "alta" | "media" | "baja";
    ownerSuggestion: string;
    targetDateSuggestion: string;
  }[];
  suggestedEvidence: {
    sectionKey: StrategicSectionKey;
    category: string;
    reason: string;
  }[];
  suggestedFieldValues: {
    sectionKey: StrategicSectionKey;
    fieldPath: string;
    suggestedValue: string;
    rationale: string;
  }[];
  confidence: "low" | "medium" | "high";
  suggestionId: string;
};

export const STRATEGIC_EVIDENCE_CATEGORY_OPTIONS: Record<StrategicSectionKey, string[]> = {
  technical: ["Certificacion ISO", "Certificacion tecnica", "Ficha tecnica", "Catalogo de productos", "Otro"],
  experience: ["Contrato previo", "Carta de recomendacion", "Constancia de cumplimiento", "Caso de exito", "Otro"],
  organization: ["Organigrama", "Politica de cumplimiento", "Manual de procesos", "Acta constitutiva", "Otro"],
  publicProcurement: ["Propuesta tecnica previa", "Propuesta economica previa", "Bases de licitacion", "Capacitacion en licitaciones", "Otro"],
};

export const CONTRACT_TYPE_OPTIONS = ["Adquisiciones", "Servicios", "Obra publica", "Arrendamiento", "Consultoria", "Mantenimiento"];

export const TEAM_AVAILABILITY_OPTIONS = [
  "No tenemos equipo dedicado",
  "Equipo parcial (segun proyecto)",
  "Equipo dedicado medio tiempo",
  "Equipo dedicado tiempo completo",
];

export const ORGANIZATION_STRUCTURE_OPTIONS = ["Funcional", "Matricial", "Por proyectos", "Jerarquica tradicional", "Mixta"];

export const STRATEGIC_DEFAULT_DATA: StrategicDiagnosticData = {
  technical: {
    productsServicesDescription: "",
    installedCapacityEmployees: "",
    equipment: "",
    infrastructure: "",
    coverageRegions: [],
    responseTimes: "",
    certifications: [],
  },
  experience: {
    hasGovernmentSectorExperience: false,
    hasPrivateSectorExperience: false,
    sectorsServed: [],
    contractTypes: [],
    approximateContractAmounts: "",
    successCases: "",
  },
  organization: {
    structureType: "",
    roles: {
      generalManagement: false,
      legal: false,
      finance: false,
      operations: false,
    },
    compliance: {
      fiscal: false,
      labor: false,
      documentedProcesses: false,
    },
  },
  publicProcurement: {
    processKnowledgeLevel: 1,
    hasTenderBasesExperience: false,
    technicalProposalCapacityLevel: 1,
    administrativeRequirementsCapacityLevel: 1,
    hasBiddingTeam: false,
    biddingTeamAvailability: TEAM_AVAILABILITY_OPTIONS[0],
  },
};
