/**
 * シルギア 相続税・贈与税の速算表API v1 の型定義
 * https://api.shirugear.com/sozoku/
 *
 * 相続税の速算表・基礎控除・法定相続分・端数処理・税額控除と加算の決まりと、
 * 贈与税の速算表（特例税率・一般税率）・相続時精算課税の決まりを返します。
 * 条文と照らし合わせた日を data_version（"YYYY-MM-DD"）で返します。金額はすべて円の整数です。
 *
 * 互換の方針: v1 の中では項目を「足す」ことはあっても、名前や意味は変えません。
 * 知らない項目が増えていても無視してください。
 */

/** 速算表の1行。税額 = 金額 × rate − deduction（金額が over を超え upto 以下のとき） */
export interface Bracket {
  over: number;
  /** 最後の区分は null */
  upto: number | null;
  /** 税率（0.1 は10%） */
  rate: number;
  /** 控除額（円） */
  deduction: number;
}

export interface Inheritance {
  name: string;
  /** 対象（"2015年1月1日以後に開始した相続"） */
  applies_to: string;
  /** 法定相続分に応ずる取得金額の速算表（8区分） */
  brackets: Bracket[];
  basic_deduction: {
    /** 3,000万円 */
    base: number;
    /** 法定相続人1人あたり600万円 */
    per_heir: number;
    rule: string;
    /** 法定相続人の数に入れる養子の上限 */
    adopted_limit: { with_real_child: number; without_real_child: number };
    law: string;
  };
  /** 法定相続分（"1/2" などの文字）と同じ順位の分け方 */
  legal_shares: {
    spouse_and_children: { spouse: string; others: string };
    spouse_and_parents: { spouse: string; others: string };
    spouse_and_siblings: { spouse: string; others: string };
    rule: string;
    law: string;
  };
  /** 相続税の総額の計算の手順 */
  steps: string[];
  rounding: Record<string, string>;
  adjustments: {
    spouse: { min_amount: number; rule: string; law: string };
    surcharge: { rate: number; rule: string; law: string };
    minor: { per_year: number; until_age: number; rule: string; law: string };
    disability: { per_year: number; per_year_special: number; until_age: number; rule: string; law: string };
    life_insurance: { per_heir: number; rule: string; law: string };
    gift_addback: { rule: string; law: string };
  };
  not_included: string;
  data_version: string;
}

export interface Gift {
  name: string;
  /** 暦年課税 */
  calendar: {
    /** 基礎控除（110万円） */
    basic_deduction: number;
    basic_deduction_law: string;
    /** 特例贈与財産（直系尊属から1月1日に18歳以上の子・孫へ）の特例税率 */
    special: { who: string; brackets: Bracket[]; law: string };
    /** 一般贈与財産の一般税率 */
    general: { who: string; brackets: Bracket[]; law: string };
    steps: string[];
  };
  /** 相続時精算課税 */
  settlement: {
    name: string;
    who: string;
    /** 毎年の基礎控除（110万円） */
    basic_deduction: number;
    /** 基礎控除が使える贈与の始まり（"2024-01-01"） */
    basic_deduction_from: string;
    /** 特別控除の累計の上限（2,500万円） */
    special_deduction: number;
    /** 税率（0.2） */
    rate: number;
    rule: string;
    law: string;
  };
  rounding: Record<string, string>;
  not_included: string;
  data_version: string;
}

export interface Meta {
  data_version: string;
  checked_at: string;
  files: ("inheritance" | "gift")[];
  /** 照合した条文の版（施行日） */
  law: Record<string, string>;
  scope: string;
  sources: { label: string; url: string }[];
}

export interface ApiError {
  error: {
    status: number;
    code: "invalid_request" | "not_found" | "region_not_allowed" | "method_not_allowed";
    message: string;
  };
}
