"""Offline interpretation fixtures for a documented geoblock response.
No network, location detection, raw-IP logging, credentials or orders.
A result never grants trading permission. Run: python3 polymarket-geoblock-check.py
"""


def classify_response(http_status, payload):
    if type(http_status) is not int or http_status != 200:
        return "UNKNOWN_CHECK_SUPPORT"
    if not isinstance(payload, dict) or type(payload.get("blocked")) is not bool:
        return "UNKNOWN_CHECK_SUPPORT"
    if payload["blocked"]:
        return "BLOCKED_DO_NOT_OPEN"
    return "IP_CHECK_CLEAR_ELIGIBILITY_NOT_ESTABLISHED"


if __name__ == "__main__":
    fixtures = [
        (200, {"blocked": True}, "BLOCKED_DO_NOT_OPEN"),
        (200, {"blocked": False}, "IP_CHECK_CLEAR_ELIGIBILITY_NOT_ESTABLISHED"),
        (200, {"blocked": "false"}, "UNKNOWN_CHECK_SUPPORT"),
        (200, {"blocked": 0}, "UNKNOWN_CHECK_SUPPORT"),
        (200, {}, "UNKNOWN_CHECK_SUPPORT"),
        (200, None, "UNKNOWN_CHECK_SUPPORT"),
        (403, {"blocked": False}, "UNKNOWN_CHECK_SUPPORT"),
        (500, {"blocked": False}, "UNKNOWN_CHECK_SUPPORT"),
        ("200", {"blocked": False}, "UNKNOWN_CHECK_SUPPORT"),
    ]
    for status, body, expected in fixtures:
        assert classify_response(status, body) == expected
    # Location-looking fields do not override the boolean/status contract.
    assert classify_response(200, {"blocked": True, "country": "ZZ", "region": "X"}) == "BLOCKED_DO_NOT_OPEN"
    assert "ALLOW" not in classify_response(200, {"blocked": False})
    print("9 status/schema fixtures and extra-field check passed.")
    print("blocked=true: stop opening; blocked=false: eligibility not established; error/missing: unknown.")
    print("No real request, IP address or user location was read or logged.")
