import requests, json, sys

BASE = "https://vap.proactiveevents.in/utilities"
# BASE = "http://192.168.29.19:8000/utilities"

def validate_bill(service: str, provider: str, fields: dict, timeout=30):
    url = f"{BASE}/api/bills/validate/"
    payload = {
        "service": service,
        "provider": provider,
        "fields": fields
    }
    print("\nPOST", url)
    print("Payload:", json.dumps(payload))
    print(url)
    try:
        # print('------------------------')
        resp = requests.post(url, json=payload, timeout=timeout)
        # print(resp)
    except Exception as e:
        print("Request error:", e)
        return

    print("Status:", resp.status_code, "| Content-Type:", resp.headers.get("content-type"))
    try:
        data = resp.json()
        print(json.dumps(data, indent=2))
    except ValueError:
        # not JSON (e.g., Django HTML error page) – show snippet
        print(resp.text[:1000])

# --- FASTag test (provider BAJF) ---
# Try both cases for the vehicle number; backend should treat case-insensitively.
validate_bill("FASTag", "BAJF", {"number": "AP15BE3333"})
# You can also try a slightly different plate to reproduce error handling:
# validate_bill("fastag", "BAJF", {"vehicle_number": "ap15be333"})  # shorter -> likely error

