import reference from "./data/REFERENTIEL_CHECKLISTS_DAACT_ENRGETIC.json";

export type DaactCode = "PPR" | "RE" | "RESP" | "RGA";
export type ChecklistCategory = "administratif" | "technique" | "photos";

type SourceItem = {
  id: string;
  label: string;
  requirement: string;
  minimum: string;
  discharge_allowed: boolean;
  condition: string;
  accepted_evidence: string[];
  notes: string;
};

type SourceChecklist = {
  title: string;
  documents: SourceItem[];
  photos: SourceItem[];
  manual: SourceItem[];
};

type ChecklistReference = {
  common: { documents: SourceItem[]; photos: SourceItem[] };
  checklists: Record<string, SourceChecklist>;
};

export type ClientChecklistItem = SourceItem & {
  category: ChecklistCategory;
};

const source = reference as ChecklistReference;

const CHECKLIST_KEYS: Record<DaactCode, string> = {
  PPR: "sismique",
  RE: "re2020_complete",
  RESP: "re_simplifiee",
  RGA: "rga",
};

export const DAACT_PRESENTATION: Record<
  DaactCode,
  { title: string; short: string; icon: string; formsKey: "sismique" | "re2020" | "rga" }
> = {
  PPR: { title: "DAACT Sismique", short: "Sismique", icon: "/risks/sismique.jpg", formsKey: "sismique" },
  RE: { title: "DAACT RE2020", short: "RE2020", icon: "/risks/re2020.jpg", formsKey: "re2020" },
  RESP: { title: "DAACT RE simplifiée", short: "RE simplifiée", icon: "/risks/re2020.jpg", formsKey: "re2020" },
  RGA: { title: "DAACT RGA", short: "RGA", icon: "/risks/rga.jpg", formsKey: "rga" },
};

export function getClientChecklist(code: DaactCode): ClientChecklistItem[] {
  const checklist = source.checklists[CHECKLIST_KEYS[code]];
  if (!checklist) return [];

  return [
    ...source.common.documents.map((item) => ({ ...item, category: "administratif" as const })),
    ...source.common.photos.map((item) => ({ ...item, category: "photos" as const })),
    ...checklist.documents.map((item) => ({ ...item, category: "technique" as const })),
    ...checklist.photos.map((item) => ({ ...item, category: "photos" as const })),
  ];
}

