/**
 * Accounting completion scoreboard — keep in sync with docs/frontend/completion-scoreboard.md
 */
export type ScoreState = "complete" | "partial" | "missing" | "blocked";

export type ModuleScore = {
  id: string;
  label: string;
  href: string;
  percent: number;
  state: ScoreState;
  note?: string;
};

export const ACCOUNTING_MODULE_SCORES: ModuleScore[] = [
  { id: "dashboard", label: "داشبورد", href: "/accounting", percent: 95, state: "complete" },
  { id: "coa", label: "دفتر حساب‌ها", href: "/accounting/chart-of-accounts", percent: 98, state: "complete" },
  { id: "fiscal", label: "سال و دوره مالی", href: "/accounting/fiscal", percent: 98, state: "complete" },
  { id: "currencies", label: "ارزها", href: "/accounting/currencies", percent: 98, state: "complete" },
  { id: "cost-centers", label: "مراکز هزینه", href: "/accounting/cost-centers", percent: 95, state: "complete" },
  { id: "projects", label: "پروژه‌ها", href: "/accounting/projects", percent: 95, state: "complete" },
  { id: "vouchers", label: "اسناد", href: "/accounting/vouchers", percent: 96, state: "complete" },
  { id: "ledger", label: "دفتر کل", href: "/accounting/ledger", percent: 95, state: "complete" },
  {
    id: "treasury",
    label: "خزانه",
    href: "/accounting/treasury",
    percent: 88,
    state: "partial",
    note: "لیست/ثبت چک و انتقال؛ ضمانت/تسهیلات هنوز ops",
  },
  { id: "customers", label: "مشتریان", href: "/accounting/customers", percent: 92, state: "complete" },
  {
    id: "suppliers",
    label: "تأمین‌کنندگان",
    href: "/accounting/suppliers",
    percent: 80,
    state: "partial",
    note: "لیست/ایجاد؛ PATCH بک‌اند ندارد",
  },
  {
    id: "sales",
    label: "فروش حسابداری",
    href: "/accounting/sales/invoices",
    percent: 85,
    state: "partial",
    note: "فاکتور + preview/post؛ فرصت/سفارش هنوز ops",
  },
  {
    id: "purchase",
    label: "خرید/انبار",
    href: "/accounting/purchase/goods-receipts",
    percent: 85,
    state: "partial",
    note: "رسید کالا + valuation متصل",
  },
  {
    id: "assets",
    label: "دارایی‌ها",
    href: "/accounting/assets",
    percent: 88,
    state: "partial",
    note: "ثبت/استهلاک/برنامه؛ انتقال/فروش ops",
  },
  { id: "payroll", label: "حقوق", href: "/accounting/payroll", percent: 90, state: "complete" },
  {
    id: "reports",
    label: "گزارش‌ها",
    href: "/accounting/reports",
    percent: 90,
    state: "partial",
    note: "تراز/ترازنامه/سود و زیان زنده؛ سایر انواع ops",
  },
  { id: "audit", label: "حسابرسی", href: "/accounting/audit", percent: 90, state: "complete" },
  {
    id: "compliance",
    label: "انطباق",
    href: "/accounting/compliance/policies",
    percent: 82,
    state: "partial",
    note: "سیاست/ریسک متصل؛ SoD هنوز ops",
  },
  { id: "settings", label: "تنظیمات", href: "/accounting/settings", percent: 80, state: "partial" },
  { id: "setup", label: "راه‌اندازی", href: "/accounting/setup", percent: 95, state: "complete" },
  {
    id: "ai",
    label: "هوش مصنوعی",
    href: "/accounting",
    percent: 0,
    state: "blocked",
    note: "منتظر Active شدن AI Provider",
  },
];

export function overallCompletionPercent(scores = ACCOUNTING_MODULE_SCORES): number {
  const active = scores.filter((s) => s.state !== "blocked");
  if (!active.length) return 0;
  return Math.round(active.reduce((a, s) => a + s.percent, 0) / active.length);
}
