/**
 * シルギア 法定相続分・遺留分API v1 の型定義
 * https://api.shirugear.com/sozokubun/
 *
 * 民法の相続の順位・法定相続分・代襲相続・半血の兄弟姉妹・遺留分の決まりと、
 * 基本の組み合わせの早見表を返します。割合は "1/4" のような分数の文字です（"0" は無し）。
 *
 * 互換の方針: v1 の中では項目を「足す」ことはあっても、名前や意味は変えません。
 * 知らない項目が増えていても無視してください。
 */

export interface Heir {
  role: "spouse" | "child" | "ascendant" | "sibling";
  /** "配偶者"・"子1"・"父母"・"兄弟姉妹2" など */
  label: string;
  /** 法定相続分（分数の文字） */
  share: string;
  /** 遺留分（分数の文字。兄弟姉妹は "0"） */
  reserved: string;
}

export interface Row {
  /** 配偶者がいるか */
  spouse: boolean;
  /** 配偶者と一緒に相続する人の種類。配偶者だけなら null */
  kind: "children" | "parents" | "grandparents" | "siblings" | null;
  /** その人数（配偶者だけなら 0） */
  count: number;
  heirs: Heir[];
}

export interface Shares {
  name: string;
  /** 順位・法定相続分・遺留分の決まり（文と分数の文字） */
  rules: {
    order: Record<string, string>;
    shares: {
      spouse_and_children: { spouse: string; others: string };
      spouse_and_ascendants: { spouse: string; others: string };
      spouse_and_siblings: { spouse: string; others: string };
      equal: string;
      half_blood: string;
      substitution: string;
      law: string;
    };
    reserved: { ascendants_only: string; others: string; siblings: string; rule: string; spouse_with_siblings: string; law: string };
    not_included: string;
  };
  /** 基本の組み合わせの早見表（配偶者の有無 × 子1〜6人・父母1〜2人・祖父母1〜4人・兄弟姉妹1〜6人、配偶者だけ） */
  table: Row[];
  data_version: string;
}

export interface Meta {
  data_version: string;
  checked_at: string;
  files: "shares"[];
  law: { civil_code: string };
  counts: { table: number };
  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;
  };
}
