// LongTermCareInsuranceSystem_Web — 画面固有設定（app-core.js が window.SYSTEM_CONFIG を読む）
window.SYSTEM_CONFIG = {
  domains: [
  { id: "ltc-insured", label: "被保険者", endpoint: "/api/ltc-insured",
    cols: [{ key: "insuredNumber", label: "被保険者番号" }, { key: "fullName", label: "氏名" }, { key: "birthDate", label: "生年月日" }, { key: "category", label: "被保険者区分" }, { key: "status", label: "状態", badge: true }],
    createFields: [{ name: "fullName", label: "氏名", required: true, placeholder: "山田 太郎" }, { name: "birthDate", label: "生年月日", required: true, type: "date" }, { name: "address", label: "住所", required: true, placeholder: "東京都..." }] },
  { id: "care-assessments", label: "要介護認定申請", endpoint: "/api/care-assessments",
    cols: [{ key: "insuredId", label: "被保険者ID" }, { key: "applicationDate", label: "申請日" }, { key: "certifiedLevel", label: "認定区分" }, { key: "status", label: "状態", badge: true }, { key: "createdAt", label: "受付日時" }],
    createFields: [{ name: "insuredId", label: "被保険者ID", required: true, placeholder: "登録済み被保険者のIDを入力" }, { name: "applicationDate", label: "申請日", required: true, type: "date" }] },
  { id: "care-services", label: "介護サービス", endpoint: "/api/care-services",
    cols: [{ key: "insuredId", label: "被保険者ID" }, { key: "serviceType", label: "サービス種別" }, { key: "provider", label: "提供事業者" }, { key: "startDate", label: "開始日" }, { key: "status", label: "状態", badge: true }],
    createFields: [{ name: "insuredId", label: "被保険者ID", required: true, placeholder: "登録済み被保険者のIDを入力" }, { name: "serviceType", label: "サービス種別", required: true, placeholder: "訪問介護" }, { name: "startDate", label: "開始日", required: true, type: "date" }, { name: "provider", label: "提供事業者名", placeholder: "○○介護サービス" }] },
],
  calc: { title: "介護保険料の試算", endpoint: "/api/kaigo/premium", primary: { key: "annual", label: "年間保険料", format: "yen" }, fields: [ { key: "baseAnnual", label: "基準額（年額）", type: "number", default: 78000 }, { key: "stage", label: "所得段階（1〜13）", type: "number", placeholder: "例: 5" } ] },
  // 中間サーバ照会（別表: 介護保険資格賦課事務）。所得→所得段階の換算はデモ用の簡易版（実際は課税状況・年金収入等で判定）
  linkage: {
    agency: "kaigo", procedure: "介護保険資格賦課事務",
    queries: [ { holder: "tax", item: "所得金額" } ],
    apply(values, setField) {
      const income = values["所得金額"];
      if (income === undefined) return false;
      const stage = income <= 0 ? 1
        : income < 1200000 ? 7 : income < 2100000 ? 8 : income < 3200000 ? 9
        : income < 4200000 ? 10 : income < 5200000 ? 11 : income < 6200000 ? 12 : 13;
      setField("stage", String(stage));
      return true;
    },
  },
};
