// The 'general' chart template — the original "Start fresh" starter chart
// (Task 4 of docs/superpowers/plans/2026-07-31-local-app.md), refactored in
// Task 1 of docs/superpowers/plans/2026-08-02-chart-templates.md into
// spine (core.ts) + two general income accounts. The composed result is
// REQUIRED to reproduce the pre-refactor 40-account chart exactly — same
// codes, names, kinds — so the sample seeder, existing tests, and every
// company already stamped from it see zero change. A hardcoded
// snapshot-equality test enforces this (tests/server/chart-templates.test.ts).
// SANCTIONED CHANGE 2026-08-02 (chart-management milestone, Task 1): every
// row additionally carries a `subtype` (presentation grouping, migration
// 0016). Codes, names, and types remain byte-identical to the pre-refactor
// chart; the snapshot test compares exactly those three fields.
//
// Curated so a brand-new company NEVER faces an empty chart (CLAUDE.md §9:
// "Categories, not account numbers... a user must never face an empty
// chart"). Types are the five ledger types the `accounts.type` CHECK
// constraint enforces directly (db/migrations/0002_ledger_core.sql).

import type { ChartTemplate, TemplateAccount as TemplateAccountRow } from "./types.js";
import { composeChart } from "./core.js";

// Legacy re-exports — this module was the original home of these types.
export type { LedgerType, TemplateAccount } from "./types.js";

export const GENERAL_TEMPLATE: ChartTemplate = Object.freeze({
  key: "general",
  label: "General small business",
  blurb: "A solid starting point that fits most small businesses.",
  examples: Object.freeze(["Sales Income", "Service Income", "Office Supplies"]),
  accounts: composeChart([
    { code: "4000", name: "Sales Income", type: "income", subtype: "income" },
    { code: "4010", name: "Service Income", type: "income", subtype: "income" },
  ]),
});

/**
 * Legacy export kept for compatibility with the original single-template
 * API shape ({ template: "small-business" }), which setup.ts still accepts
 * as an alias for 'general'.
 */
export const SETUP_TEMPLATES: Readonly<Record<string, readonly TemplateAccountRow[]>> =
  Object.freeze({
    "small-business": GENERAL_TEMPLATE.accounts,
  });
