#!/usr/bin/env python3
"""Compare monthly cost of model options for one workflow step (lesson AUT-203-L06). Standard library only.

Input CSV columns (one row per option):
  option, calls_per_month, input_tokens, output_tokens, price_in_per_mtok, price_out_per_mtok,
  retry_rate, fixed_monthly, review_minutes_per_call, reviewer_cost_per_hour
Prices are YOUR inputs from the provider's dated pricing page; this script invents nothing.
fixed_monthly covers things like a local machine's share of hardware and power.

    python cost_compare.py options.csv
"""
import csv
import sys


def monthly(row):
    calls = float(row["calls_per_month"]) * (1 + float(row["retry_rate"]))
    model = calls * (float(row["input_tokens"]) * float(row["price_in_per_mtok"]) +
                     float(row["output_tokens"]) * float(row["price_out_per_mtok"])) / 1_000_000
    review = float(row["calls_per_month"]) * float(row["review_minutes_per_call"]) / 60 * float(row["reviewer_cost_per_hour"])
    return model, float(row["fixed_monthly"]), review


def main(path):
    rows = list(csv.DictReader(open(path, encoding="utf-8")))
    print(f"{'option':28} {'model':>10} {'fixed':>10} {'review':>10} {'total':>10}")
    for r in rows:
        m, f, v = monthly(r)
        print(f"{r['option']:28} {m:10.2f} {f:10.2f} {v:10.2f} {m + f + v:10.2f}")
    print("\nunits: same currency as your price inputs; model cost includes retries")


if __name__ == "__main__":
    if len(sys.argv) != 2:
        sys.exit("usage: python cost_compare.py OPTIONS.csv")
    main(sys.argv[1])
