export type HrAggregateScoreBreakdown = {
  totalScore: number;
  churnScore: number;
  tenureScore: number;
  headcountStabilityScore: number;
  kpiComplianceScore: number;
  weights: {
    churn: number;
    tenure: number;
    headcountStability: number;
    kpiCompliance: number;
  };
};

export type HumanCapitalWorkspaceTabKey =
  | "resumen"
  | "expedientes"
  | "nomina"
  | "reclutamiento"
  | "desarrollo"
  | "cumplimiento";

export type HumanCapitalWorkspaceWidgetKey =
  | "summary_metrics"
  | "people_files_table"
  | "payroll_summary"
  | "recruitment_headcount"
  | "recruitment_vacancies"
  | "recruitment_org_target"
  | "career_feed"
  | "compliance_overview";

export type HumanCapitalWorkspaceTabConfig = {
  key: HumanCapitalWorkspaceTabKey;
  label: string;
  description?: string;
  order: number;
  visible: boolean;
  widgets: HumanCapitalWorkspaceWidgetKey[];
};

export type HumanCapitalWorkspaceConfig = {
  tabs: HumanCapitalWorkspaceTabConfig[];
};

export type HumanCapitalWorkspaceVersion = {
  id: string;
  department: "capital_humano";
  version: number;
  status: "draft" | "published" | "archived";
  name: string;
  tabs: HumanCapitalWorkspaceTabConfig[];
  changeSummary: string | null;
  createdById: string | null;
  publishedById: string | null;
  publishedAt: string | null;
  createdAt: string;
  updatedAt: string;
};

export type HumanCapitalFileRequirementDTO = {
  id: string;
  key: string;
  label: string;
  description: string | null;
  fieldType: string;
  isRequired: boolean;
  isActive: boolean;
  sortOrder: number;
};

export type HumanCapitalPersonFileItemDTO = {
  requirementId: string;
  requirementKey: string;
  requirementLabel: string;
  fieldType: string;
  isRequired: boolean;
  status: "missing" | "submitted" | "verified" | "rejected";
  valueText: string | null;
  evidenceUrl: string | null;
  note: string | null;
  verifiedAt: string | null;
};

export type HumanCapitalPersonFilesDTO = {
  userId: string;
  name: string;
  email: string;
  department: string | null;
  departmentRole: string | null;
  locationId: string | null;
  completionPct: number;
  complete: boolean;
  items: HumanCapitalPersonFileItemDTO[];
};

export type HumanCapitalFilesListItemDTO = {
  userId: string;
  name: string;
  email: string;
  department: string | null;
  departmentRole: string | null;
  locationId: string | null;
  completionPct: number;
  complete: boolean;
  requiredMissing: number;
};

export type HumanCapitalVacancyDTO = {
  id: string;
  locationCode: string;
  roleKey: string;
  title: string;
  status: "draft" | "open" | "interviewing" | "offered" | "hired" | "closed" | "cancelled";
  priority: string;
  openedAt: string;
  targetStartAt: string | null;
  closedAt: string | null;
  notes: string | null;
};

export type HumanCapitalOrgTargetDTO = {
  id: string;
  locationCode: string;
  roleKey: string;
  targetCount: number;
  isActive: boolean;
  actualCount: number;
  gap: number;
};

export type HumanCapitalPayrollSummaryDTO = {
  periodStart: string;
  periodEnd: string;
  frequency: "weekly" | "biweekly";
  locationCode: string | null;
  percepciones: number;
  deducciones: number;
  aportaciones: number;
  neto: number;
  peopleCount: number;
};

export type HumanCapitalCareerContentDTO = {
  id: string;
  contentType: "announcement" | "course";
  title: string;
  body: string;
  sourceDepartment: string | null;
  startsAt: string | null;
  endsAt: string | null;
  isActive: boolean;
  createdAt: string;
};

export type HumanCapitalComplianceObligationDTO = {
  id: string;
  body: "imss" | "infonavit" | "fonacot" | "other";
  title: string;
  status: "on_time" | "due_soon" | "overdue" | "paid" | "blocked";
  locationCode: string | null;
  referencePeriod: string | null;
  dueDate: string | null;
  lastPaymentAt: string | null;
  lastPaymentAmount: number | null;
  notes: string | null;
};

export type HumanCapitalDashboardResponse = {
  generatedAt: string;
  summary: {
    activeHeadcount: number;
    previousHeadcount: number;
    netHeadcountChange: number;
    monthlyExits: number;
    monthlyHires: number;
    monthlyChurnPct: number;
    medianTenureMonths: number;
    kpiCompliancePct: number;
  };
  aggregateScore: HrAggregateScoreBreakdown;
  churnTrend: Array<{ month: string; churnPct: number; exits: number; hires: number }>;
  tenureBands: Array<{ label: string; count: number }>;
  updates: Array<{
    id: string;
    title: string;
    severity: "info" | "warning" | "critical";
    status: string;
    publishedAt: string | null;
  }>;
};
