import type { MrrChange, MrrPeriod, MrrMovementSnapshot } from "@lumo/widgets/catalog/saas/mrr-movement";
type LedgerPeriod = { id: string; label: string; openingMinor: number | null; confirmed: boolean; items: readonly { kind: MrrChange["kind"]; amountMinor: number }[] };
export function adapt(scope: string, currency: string, reports: readonly LedgerPeriod[]): MrrMovementSnapshot {
const kinds = ["new", "expansion", "contraction", "churn"] as const;
const periods: MrrPeriod[] = reports.map(report => ({
id: report.id, label: report.label, openingMinor: report.openingMinor,
changes: kinds.map(kind => ({ kind, amountMinor: report.confirmed
? report.items.filter(item => item.kind === kind).reduce((sum, item) => sum + item.amountMinor, 0) : null })),
}));
return { scope, currency, periods };
}