/**
 * シルギア 不動産の仲介手数料の上限API v1 の型定義
 * https://api.shirugear.com/chukai/
 *
 * 宅地建物取引業者が売買・交換・貸借の媒介・代理で受けられる報酬（仲介手数料）の上限の率（国土交通大臣の報酬告示）と、
 * 低廉な空家等・長期の空家等の特例を返します。金額はすべて円の整数、率は小数（0.055 は5.5%）です。
 *
 * 互換の方針: v1 の中では項目を「足す」ことはあっても、名前や意味は変えません。
 * 知らない項目が増えていても無視してください。
 */

/** 売買・交換の媒介の率。代金（税抜）の over を超え upto 以下の部分にかける */
export interface SaleBracket {
  over: number;
  /** 最後の区分は null */
  upto: number | null;
  /** 消費税込みの率（0.055・0.044・0.033） */
  rate_incl: number;
  /** 税抜の率（0.05・0.04・0.03） */
  rate_excl: number;
}

export interface Period {
  /** 時期の名前（"2024-07" など） */
  key: string;
  from: string;
  /** 今の時期は null */
  until: string | null;
  /** 低廉な空家等の売買の媒介の特例 */
  low_cost: {
    /** 対象の代金（税抜）の上限 */
    max_price: number;
    /** 受けられる上限（税込） */
    cap_incl: number;
    /** "client" は売主・買主の依頼者、"seller" は売主だけ */
    who: "client" | "seller";
    note: string;
  };
  /** 長期の空家等の貸借の媒介の特例（2024年7月から。それより前は null） */
  long_vacant: { total_months: number; tenant_months: number; tenant_months_residential: number; note: string } | null;
}

export interface Rates {
  name: string;
  currency: "JPY";
  sale: SaleBracket[];
  rent: {
    /** 貸主・借主の合計の上限（借賃の何か月分・税込） */
    total_months_incl: number;
    /** 居住用で承諾が無いとき、依頼者の一方からの上限（借賃の何か月分・税込） */
    one_side_residential_incl: number;
  };
  /** 売買・交換の代理は媒介の何倍まで */
  agency_multiplier: number;
  periods: Period[];
  /** 売買・賃貸・代理・権利金・消費税・広告料・端数の決まり（文で説明） */
  rules: Record<string, unknown>;
  data_version: string;
}

export interface Meta {
  data_version: string;
  checked_at: string;
  files: "rates"[];
  periods: { key: string; from: string; until: string | null }[];
  law: { notice: string; last_amendment: string; enforced: 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;
  };
}
