#!/usr/bin/env python3
"""Synthetic, offline worksheet for an authorized HTTP/browser route choice."""
from decimal import Decimal


# Replace these teaching inputs before using the arithmetic for a real approved task.
TOTAL_ITEMS = 100
JS_REQUIRED_ITEMS = 20
HTTP_MINUTES_PER_ITEM = Decimal("0.10")
BROWSER_MINUTES_PER_ITEM = Decimal("0.65")
BROWSER_SETUP_MINUTES = Decimal("8.00")
HYBRID_ROUTING_OVERHEAD_MINUTES = Decimal("2.00")


def require_nonnegative_decimal(name, value):
    if not isinstance(value, Decimal) or not value.is_finite() or value < 0:
        raise ValueError(f"{name} must be a finite non-negative Decimal")


def validate():
    if isinstance(TOTAL_ITEMS, bool) or not isinstance(TOTAL_ITEMS, int) or TOTAL_ITEMS <= 0:
        raise ValueError("TOTAL_ITEMS must be a positive integer")
    if (isinstance(JS_REQUIRED_ITEMS, bool) or not isinstance(JS_REQUIRED_ITEMS, int)
            or not 0 <= JS_REQUIRED_ITEMS <= TOTAL_ITEMS):
        raise ValueError("JS_REQUIRED_ITEMS must be between zero and TOTAL_ITEMS")
    for name, value in (
        ("HTTP_MINUTES_PER_ITEM", HTTP_MINUTES_PER_ITEM),
        ("BROWSER_MINUTES_PER_ITEM", BROWSER_MINUTES_PER_ITEM),
        ("BROWSER_SETUP_MINUTES", BROWSER_SETUP_MINUTES),
        ("HYBRID_ROUTING_OVERHEAD_MINUTES", HYBRID_ROUTING_OVERHEAD_MINUTES),
    ):
        require_nonnegative_decimal(name, value)
def minutes(value):
    return f"{value.quantize(Decimal('0.01'))} common worker-minutes"


def main():
    validate()
    http_eligible = TOTAL_ITEMS - JS_REQUIRED_ITEMS
    http_only = Decimal(TOTAL_ITEMS) * HTTP_MINUTES_PER_ITEM
    browser_only = BROWSER_SETUP_MINUTES + Decimal(TOTAL_ITEMS) * BROWSER_MINUTES_PER_ITEM
    hybrid_direct = (BROWSER_SETUP_MINUTES + HYBRID_ROUTING_OVERHEAD_MINUTES
              + Decimal(http_eligible) * HTTP_MINUTES_PER_ITEM
              + Decimal(JS_REQUIRED_ITEMS) * BROWSER_MINUTES_PER_ITEM)
    hybrid_http_first = (BROWSER_SETUP_MINUTES + HYBRID_ROUTING_OVERHEAD_MINUTES
                         + Decimal(TOTAL_ITEMS) * HTTP_MINUTES_PER_ITEM
                         + Decimal(JS_REQUIRED_ITEMS) * BROWSER_MINUTES_PER_ITEM)
    saved = browser_only - hybrid_direct
    extra_per_http_item = BROWSER_MINUTES_PER_ITEM - HTTP_MINUTES_PER_ITEM

    if JS_REQUIRED_ITEMS == 0:
        decision = "HTTP_ONLY because no required field needs browser execution"
    elif http_eligible == 0:
        decision = "BROWSER_ONLY because every item has a proved required rendered field"
    elif saved > 0:
        decision = "HYBRID because the JS-only fields are proved required and direct routing costs less"
    elif saved == 0:
        decision = "EQUAL_MODEL because direct hybrid and browser-only have the same modeled effort"
    else:
        decision = "BROWSER_ONLY because direct hybrid costs more in this model"

    print("Synthetic HTTP/browser route worksheet")
    print(f"Assumptions: {TOTAL_ITEMS} permitted items; {JS_REQUIRED_ITEMS} have a required field absent from the authorized HTTP representation.")
    print("All values are invented common worker-minutes, not human minutes, performance measurements, or IPHTML claims.")
    print(f"HTTP-only modeled effort: {minutes(http_only)}; field status: {'INSUFFICIENT' if JS_REQUIRED_ITEMS else 'SUFFICIENT'}")
    print(f"Browser-only modeled effort: {minutes(browser_only)}")
    print(f"Direct-classified hybrid modeled effort: {minutes(hybrid_direct)}")
    print(f"HTTP-first fallback hybrid modeled effort: {minutes(hybrid_http_first)}")
    print(f"Direct hybrid difference versus browser-only: {minutes(saved)}")
    print(f"Each HTTP-eligible item kept out of the browser changes effort by: {minutes(extra_per_http_item)}")
    print(f"Decision: {decision}.")
    print("Boundary: direct hybrid requires a preclassified subset; pilot/classification cost is outside this batch model.")
    print("PASS: synthetic offline worksheet only; no network, browser, files, secrets, targets, or proxy activity.")


if __name__ == "__main__":
    main()
