// Default required-document set per rank, derived from the rank flags in
// rank-data.ts. Drives candidate vetting and crew uploads (RankDocRequirement).
//   - Every crew member: Aadhaar, PAN, photograph.
//   - Seafarers additionally: STCW, CDC, passport, medical fitness (mandatory);
//     COC is conditional (officer/senior ranks only).
//   - Driver: driving licence (mandatory).
// Editable afterwards at /admin/ranks; this is just the seeded baseline.

import type { SeafarerDocType } from "@prisma/client";
import { RANKS } from "./rank-data";

export type RankDocReq = {
  rankCode: string;
  docType: SeafarerDocType;
  isMandatory: boolean;
  note?: string;
};

const COMMON: { docType: SeafarerDocType; isMandatory: boolean }[] = [
  { docType: "AADHAAR", isMandatory: true },
  { docType: "PAN", isMandatory: true },
  { docType: "PHOTOGRAPH", isMandatory: true },
];

const SEAFARER: { docType: SeafarerDocType; isMandatory: boolean; note?: string }[] = [
  { docType: "STCW", isMandatory: true },
  { docType: "CDC", isMandatory: true },
  { docType: "PASSPORT", isMandatory: true },
  { docType: "MEDICAL_FITNESS", isMandatory: true },
  { docType: "COC", isMandatory: false, note: "Officer / senior ranks only" },
];

export const RANK_DOC_REQUIREMENTS: RankDocReq[] = RANKS.flatMap((rank) => {
  const reqs: RankDocReq[] = COMMON.map((c) => ({ rankCode: rank.code, ...c }));
  if (rank.isSeafarer) {
    reqs.push(...SEAFARER.map((s) => ({ rankCode: rank.code, ...s })));
  }
  if (rank.code === "DRV") {
    reqs.push({ rankCode: "DRV", docType: "DRIVING_LICENSE", isMandatory: true });
  }
  return reqs;
});
