/**
 * シルギア 最低賃金API v1 の型定義
 * https://api.shirugear.com/minwage/
 *
 * 地域別最低賃金（時間額）だけを返します（特定（産業別）最低賃金は含みません）。
 * 年度の額は、その都道府県の発効日（effective_date）から適用されます。
 * 「今の額」は history（新しい順）で effective_date が今日（日本時間）以前の最初のもの。
 *
 * 互換の方針: v1 の中では項目を「足す」ことはあっても、名前や意味は変えません。
 * 知らない項目が増えていても無視してください。
 */

/** 都道府県コード2桁（JIS。"01" 北海道 〜 "47" 沖縄県） */
export type PrefCode = string;

/** ある都道府県・ある年度の額 */
export interface MinwageAmount {
  /** 地域別最低賃金の時間額（円） */
  amount: number;
  /** 発効日 "YYYY-MM-DD"。この日から適用 */
  effective_date: string;
  /** 前の年度からの引上げ額（円）。改定なしは 0、最初の年度（2002）は null */
  raise: number | null;
  /** false=前の年度から改定されていない（額も発効日も前の年度と同じ） */
  revised: boolean;
}

export interface MinwageHistoryEntry extends MinwageAmount {
  /** 年度（西暦）。令和8年度なら 2026 */
  fiscal_year: number;
  /** 和暦の年度（"令和8年度" / "令和元年度" / "平成14年度" など） */
  fiscal_year_label: string;
}

/** GET /minwage/v1/{都道府県コード2桁}.json（01〜47） */
export interface MinwagePrefectureResponse {
  pref_code: PrefCode;
  /** 都道府県名（"東京都" など） */
  pref: string;
  unit: "円/時間";
  /** 新しい年度から順 */
  history: MinwageHistoryEntry[];
  /** 厚生労働省の一覧を取り込んだ日 "YYYY-MM-DD" */
  data_version: string;
}

export interface MinwagePrefectureAmount extends MinwageAmount {
  pref_code: PrefCode;
  pref: string;
}

/** GET /minwage/v1/{年度4桁}.json（2002〜最新の年度） */
export interface MinwageFiscalYearResponse {
  fiscal_year: number;
  fiscal_year_label: string;
  unit: "円/時間";
  /** 全国加重平均額（円・厚生労働省の公表値） */
  national_weighted_average: number | null;
  /** 47都道府県の額がそろっていれば true。false のときは決まった都道府県だけが入る */
  complete: boolean;
  /** 都道府県コードの順 */
  prefectures: MinwagePrefectureAmount[];
  data_version: string;
}

/** GET /minwage/v1/all.json */
export interface MinwageAllResponse {
  /** 最初の年度（2002） */
  from: number;
  /** 最後の年度 */
  to: number;
  unit: "円/時間";
  /** キーは年度（"2026" など）→ 全国加重平均額（円） */
  national_weighted_average: Record<string, number | null>;
  prefectures: {
    pref_code: PrefCode;
    pref: string;
    /** 都道府県ごとの応答と違い、古い年度から順。項目は3つだけ */
    history: { fiscal_year: number; amount: number; effective_date: string }[];
  }[];
  data_version: string;
}

/** GET /minwage/v1/meta.json */
export interface MinwageMetaResponse {
  data_version: string;
  /** データを作った日時（ISO 8601・UTC） */
  built_at: string;
  from: number;
  to: number;
  /** いちばん新しい年度の額が47都道府県そろっていれば true */
  latest_complete: boolean;
  /** 出典の書き方 */
  source: string;
  sources: {
    name: string;
    /** 元にした Excel の URL */
    url: string;
    /** その Excel が載っているページ */
    page: string;
    /** 取得した日時（ISO 8601・UTC） */
    fetched_at: string;
  }[];
  counts: {
    /** 都道府県の数（47） */
    prefectures: number;
    /** 年度の数 */
    fiscal_years: number;
    /** 都道府県 × 年度の数 */
    records: number;
  };
}

/** エラーのときの本文 */
export interface ErrorResponse {
  error: {
    status: 400 | 403 | 404 | 405;
    code: "invalid_request" | "not_found" | "region_not_allowed" | "method_not_allowed";
    message: string;
  };
}
