# -*- coding: utf-8 -*-
"""Gemini Enterprise の席数×エディション×支払い周期から、12か月の支払額を出す（標準ライブラリのみ・外部送信なし）。
使い方: python calculator.py input.json
単価は 2026-11-13 に Google Cloud Platform SKUs（https://cloud.google.com/skus?filter=Gemini%20Enterprise）で確認した
表示値（USD と JPY は Billing Currency を切り替えた表示値。為替換算ではない）。税は含まない。
input.json の例: {"seats": 50, "edition": "standard", "term": "annual", "tax_rate": 0.10}
  edition: business / standard / plus / frontline   term: monthly / annual
"""
import json, sys
PRICES = {
    "business": {
        "label": "Business",
        "monthly_usd": 25.0,
        "annual_usd": 21.0,
        "monthly_jpy": 3700,
        "annual_jpy": 3100,
        "seats": "1〜500人"
    },
    "standard": {
        "label": "Standard",
        "monthly_usd": 35.0,
        "annual_usd": 30.0,
        "monthly_jpy": 5100,
        "annual_jpy": 4400,
        "seats": "1人以上"
    },
    "plus": {
        "label": "Plus",
        "monthly_usd": 60.0,
        "annual_usd": 50.0,
        "monthly_jpy": 8800,
        "annual_jpy": 7300,
        "seats": "1人以上"
    },
    "frontline": {
        "label": "Frontline",
        "monthly_usd": 15.0,
        "annual_usd": 12.5,
        "monthly_jpy": 2200,
        "annual_jpy": 1800,
        "seats": "Standard／Plus が150人以上"
    }
}
TAX_DEFAULT = 0.1

def calc(seats, edition, term, tax_rate=TAX_DEFAULT):
    if edition not in PRICES:
        raise ValueError("edition は business / standard / plus / frontline のどれか")
    if term not in ("monthly", "annual"):
        raise ValueError("term は monthly / annual のどちらか")
    if not isinstance(seats, int) or seats < 1:
        raise ValueError("seats は1以上の整数")
    if edition == "business" and seats > 500:
        raise ValueError("Business エディションの上限は 500 ユーザー（公式ヘルプ。Business ページは『最大 300 名』で食い違う）。Standard／Plus を見る")
    if not (0 <= tax_rate < 1):
        raise ValueError("tax_rate は 0 以上 1 未満の小数（10% なら 0.10）")
    p = PRICES[edition]
    note = "Frontline は Standard／Plus のユーザーが 150 人以上の組織向け（公式ドキュメント）。Frontline の席数ではなく Standard／Plus の人数で判定される" if edition == "frontline" else ""
    usd = p[term + "_usd"] * seats * 12
    jpy = p[term + "_jpy"] * seats * 12
    return {
        "edition": p["label"], "term": term, "seats": seats,
        "per_seat_month_usd": p[term + "_usd"], "per_seat_month_jpy": p[term + "_jpy"],
        "year_usd": round(usd, 2), "year_jpy": jpy,
        "year_jpy_with_tax": round(jpy * (1 + tax_rate)),
        "saving_vs_monthly_jpy": (p["monthly_jpy"] - p["annual_jpy"]) * seats * 12 if term == "annual" else 0,
        "note": note,
    }

if __name__ == "__main__":
    path = sys.argv[1] if len(sys.argv) > 1 else "input.json"
    with open(path, encoding="utf-8") as f:
        cfg = json.load(f)
    r = calc(int(cfg["seats"]), cfg["edition"], cfg["term"], float(cfg.get("tax_rate", TAX_DEFAULT)))
    print(json.dumps(r, ensure_ascii=False, indent=2))
