Files
eu/lib/acts/flows.ts
T
2026-07-28 17:05:45 +03:00

48 lines
1.9 KiB
TypeScript

export type ActCapability =
| "SIGN_FEDERAL_LAW_SENATE"
| "SIGN_FEDERAL_LAW_HOUSE"
| "SIGN_AS_HEAD_OF_STATE"
| "SIGN_SENATE_APPOINTMENT"
| "SIGN_TREATY"
| "SIGN_RATIFICATION"
| "SIGN_REGIONAL_ACT";
export type FlowPhase = {
key: string;
label: string;
capability: ActCapability;
isFinal: boolean;
allowVeto?: boolean;
vetoLabel?: string;
};
export type ActFlow = FlowPhase[];
const singleSignature = (capability: ActCapability, label: string): ActFlow => [
{ key: "ADOPTION", label, capability, isFinal: true, allowVeto: true, vetoLabel: "Reject" },
];
const FEDERAL_LAW_FLOW: ActFlow = [
{ key: "SENATE_ADOPTION", label: "Awaiting the Senate", capability: "SIGN_FEDERAL_LAW_SENATE", isFinal: false, allowVeto: true, vetoLabel: "Reject" },
{ key: "HOUSE_ADOPTION", label: "Awaiting the House of Representatives", capability: "SIGN_FEDERAL_LAW_HOUSE", isFinal: false, allowVeto: true, vetoLabel: "Reject" },
{ key: "PRESIDENT_DECISION", label: "Under review by the President", capability: "SIGN_AS_HEAD_OF_STATE", isFinal: true, allowVeto: true, vetoLabel: "Veto" },
];
const FLOWS_BY_ACT_TYPE_CODE: Record<string, ActFlow> = {
FEDERAL_LAW: FEDERAL_LAW_FLOW,
SENATE_APPOINTMENT: singleSignature("SIGN_SENATE_APPOINTMENT", "Awaiting the Senate"),
TREATY: singleSignature("SIGN_TREATY", "Awaiting the President's signature"),
RATIFICATION_ACT: singleSignature("SIGN_RATIFICATION", "Awaiting the Senate"),
REGIONAL_ACT: singleSignature("SIGN_REGIONAL_ACT", "Awaiting the regional government"),
};
export function getActFlow(actTypeCode: string): ActFlow {
const flow = FLOWS_BY_ACT_TYPE_CODE[actTypeCode];
if (!flow) throw new Error(`No flow configured for act type "${actTypeCode}"`);
return flow;
}
export function getNextPhase(flow: ActFlow, approvals: { phaseKey: string }[]): FlowPhase | undefined {
const done = new Set(approvals.map((a) => a.phaseKey));
return flow.find((p) => !done.has(p.key));
}