"""Reproduce one real-market Treasury bill cash-benchmark calculation.

The disclosed input is a minimal subset of an official U.S. Treasury auction
result. This is a methodology/reproducibility example, not strategy performance,
a recommendation, or evidence of investment outperformance.

The script is intentionally runnable from the reviewed public bundle with only
the Python standard library and no network access.
"""

from __future__ import annotations

import json
import sys
from pathlib import Path
from typing import Any

PUBLIC_ROOT = Path(__file__).resolve().parents[1]
if str(PUBLIC_ROOT) not in sys.path:
    sys.path.insert(0, str(PUBLIC_ROOT))

from calculations import compute_treasury_bill_cash_benchmark

INPUT_PATH = PUBLIC_ROOT / "data" / "treasury_bill_2025-06-30.json"


def build_example() -> dict[str, Any]:
    source = json.loads(INPUT_PATH.read_text(encoding="utf-8"))
    auction = source["auction"]

    result = compute_treasury_bill_cash_benchmark(
        purchase_price_per_100=float(auction["price_per_100"]),
        term_days=int(auction["term_days"]),
    )
    published_rate_pct = float(auction["published_investment_rate_pct"])
    difference_pct_points = result.simple_annualized_rate_pct - published_rate_pct

    return {
        "schema_version": "0.1",
        "evidence_class": "real_market_cash_benchmark_calculation",
        "not_strategy_performance_evidence": True,
        "purpose": (
            "Show that a disclosed official Treasury bill auction price can be "
            "converted into a reproducible holding-period and annualized cash return."
        ),
        "source": {
            "publisher": source["publisher"],
            "dataset": source["dataset"],
            "auction_date": auction["auction_date"],
            "issue_date": auction["issue_date"],
            "maturity_date": auction["maturity_date"],
            "source_dataset_url": source["source_dataset_url"],
            "source_auction_result_url": source["source_auction_result_url"],
        },
        "inputs": {
            "price_per_100": auction["price_per_100"],
            "maturity_value_per_100": 100.0,
            "term_days": auction["term_days"],
            "published_investment_rate_pct": published_rate_pct,
        },
        "calculation": {
            **result.to_dict(),
            "annualization_formula": (
                "((100 / purchase_price_per_100) - 1) * (365 / term_days)"
            ),
            "published_rate_difference_percentage_points": difference_pct_points,
            "published_rate_matches_within_0_001_pct_point": (
                abs(difference_pct_points) <= 0.001
            ),
            "runtime_dependency": "python_standard_library_only",
            "network_required": False,
        },
        "warnings": [
            "This is a Treasury cash-benchmark calculation primitive, not strategy performance.",
            "It does not establish superiority to cash, passive investing, or any benchmark.",
            "The published Treasury investment rate is rounded to three decimal places.",
        ],
    }


def main() -> int:
    print(json.dumps(build_example(), indent=2, sort_keys=True))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
