// KokuhoWebSystem — 画面固有設定（app-core.js が window.SYSTEM_CONFIG を読む）
window.SYSTEM_CONFIG = {
  domains: [
  { id: "kokuho-households", label: "世帯", endpoint: "/api/kokuho-households",
    cols: [{ key: "householdNumber", label: "世帯番号" }, { key: "householderName", label: "世帯主氏名" }, { key: "address", label: "住所" }, { key: "status", label: "状態", badge: true }, { key: "createdAt", label: "登録日時" }],
    createFields: [{ name: "householderName", label: "世帯主氏名", required: true, placeholder: "山田 太郎" }, { name: "address", label: "住所", required: true, placeholder: "東京都..." }] },
  { id: "kokuho-insured", label: "被保険者", endpoint: "/api/kokuho-insured",
    cols: [{ key: "insuredNumber", label: "被保険者番号" }, { key: "householdId", label: "世帯ID" }, { key: "fullName", label: "氏名" }, { key: "birthDate", label: "生年月日" }, { key: "status", label: "状態", badge: true }],
    createFields: [{ name: "householdId", label: "世帯ID", required: true, placeholder: "登録済み世帯のIDを入力" }, { name: "fullName", label: "氏名", required: true, placeholder: "山田 花子" }, { name: "birthDate", label: "生年月日", required: true, type: "date" }, { name: "relationship", label: "続柄", placeholder: "配偶者" }] },
  { id: "kokuho-levies", label: "賦課", endpoint: "/api/kokuho-levies",
    cols: [{ key: "householdId", label: "世帯ID" }, { key: "fiscalYear", label: "年度" }, { key: "amount", label: "賦課額" }, { key: "paidAmount", label: "納付額" }, { key: "status", label: "状態", badge: true }],
    createFields: [{ name: "householdId", label: "世帯ID", required: true, placeholder: "登録済み世帯のIDを入力" }, { name: "fiscalYear", label: "年度", required: true, placeholder: "2026" }, { name: "amount", label: "賦課額（円）", required: true, type: "number", placeholder: "120000" }] },
],
  calc: { title: "国保保険料の試算", endpoint: "/api/kokuho/premium", primary: { key: "total", label: "年間保険料", format: "yen" }, fields: [ { key: "members", label: "被保険者（所得:年齢 を改行区切り）", type: "members", placeholder: "2000000:45\n0:70" } ] },
  // 中間サーバ照会（別表: 国民健康保険資格賦課事務）。世帯主=照会所得・他の世帯員=所得0として展開（デモ用の簡易展開）
  linkage: {
    agency: "kokuho", procedure: "国民健康保険資格賦課事務",
    queries: [ { holder: "tax", item: "所得金額" }, { holder: "juki", item: "世帯人数" } ],
    apply(values, setField) {
      const income = values["所得金額"];
      if (income === undefined) return false;
      const n = Math.max(1, Number(values["世帯人数"] || 1));
      setField("members", [`${income}:45`, ...Array(n - 1).fill("0:40")].join("\n"));
      return true;
    },
  },
};
