"""Synthetic monthly records: a rule demonstration, not a finance integration."""

import json
import re

# Order creation and accounting recognition answer different questions.
ORDER_VALUE_CENTS = {"2026-01": 10_500_000, "2026-02": 11_000_000}
MONTH_CLOSE = {
    "2026-01": {"closed": True, "net_cents": 10_000_000, "cutoff": "2026-02-03T18:00:00Z"},
    "2026-02": {"closed": True, "net_cents": 9_200_000, "cutoff": "2026-03-03T18:00:00Z"},
    "2026-03": {"closed": False, "net_cents": None, "cutoff": None},
}


def closed_month_net_revenue(month: str) -> dict:
    if not isinstance(month, str) or not re.fullmatch(r"[0-9]{4}-(0[1-9]|1[0-2])", month):
        raise ValueError("month must be YYYY-MM")
    record = MONTH_CLOSE.get(month)
    if record is None:
        raise ValueError("month is not available in the approved source")
    if not record["closed"]:
        raise ValueError("month is not closed; do not substitute order value")
    return {
        "month": month,
        "amount_cents": record["net_cents"],
        "currency": "USD",
        "definition": "recognized revenue minus recognized refunds; excludes sales tax",
        "scope": "fictional company total",
        "cutoff": record["cutoff"],
        "source": f"synthetic-month-close/{month}",
        "status": "closed",
    }


if __name__ == "__main__":
    print(json.dumps(closed_month_net_revenue("2026-02"), indent=2))
