/** Project inception (milestone 297): what a project was decided to inherit. */
import { apiGet, apiPost } from "@/api/client";

export interface InceptionChoices {
  exclude_always_on_rulebooks: number[];
  subscribe_rulebooks: number[];
  design_system_id: number | null;
  seed_systems: boolean;
}

export interface InceptionRecord {
  decided_at: string;
  decided_by: number | null;
  via: "mcp" | "ui" | "legacy";
  choices: InceptionChoices;
}

export interface InceptionDefaults {
  always_on_rulebooks: { id: number; title: string }[];
  other_rulebooks: { id: number; title: string }[];
  excluded_always_on: { id: number; title: string }[];
  subscribed_rulebooks: { id: number; title: string }[];
  design_system_id: number | null;
  design_systems: { id: number; title: string }[];
  systems: number;
}

export interface InceptionDecision {
  project_id: number;
  inception: InceptionRecord;
  effects: { excluded: number[]; subscribed: number[]; design_system_id: number | null; systems_seeded: string[] };
}

export const emptyChoices = (): InceptionChoices => ({
  exclude_always_on_rulebooks: [], subscribe_rulebooks: [], design_system_id: null, seed_systems: false,
});

export const fetchInceptionDefaults = (projectId: number) =>
  apiGet<InceptionDefaults>(`/api/projects/${projectId}/inception/defaults`);

export const decideInception = (projectId: number, choices: InceptionChoices) =>
  apiPost<InceptionDecision>(`/api/projects/${projectId}/inception`, { choices });
