"""Local raw-JSON checklist only. No HTTP, credentials or automatic rewriting.
Not a full native schema validator and not a gateway compatibility test.
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path

def check_request(body):
    if not isinstance(body, dict):
        return ["Expected a request object"]
    issues=[]
    if body.get("model") != "claude-sonnet-5-5":
        issues.append("Confirm the exact Sonnet5.5 route model ID")
    thinking=body.get("thinking", {"type":"adaptive"})
    if not isinstance(thinking,dict):
        issues.append("thinking must be an object")
        thinking={}
    typ=thinking.get("type")
    if typ not in ("adaptive","between_tools"):
        issues.append("This model needs adaptive or between_tools, not enabled/disabled")
    output=body.get("output_config",{})
    if not isinstance(output,dict):
        issues.append("output_config must be an object");output={}
    effort=output.get("effort","high")
    if effort not in ("low","medium","high","xhigh","max"):
        issues.append("Unknown effort level")
    if "budget_tokens" in thinking:
        issues.append("Remove the old manual thinking budget; do not auto-map it to effort")
    if typ == "between_tools":
        if set(thinking) != {"type"}:
            issues.append("between_tools takes only type, with no display/budget/binding fields")
        if effort not in ("low","medium","high"):
            issues.append("between_tools requires high effort or below")
    if typ == "adaptive" and "block_binding" in thinking:
        issues.append("Review block_binding platform/beta/gateway support manually")
    if any(x in body for x in ("temperature","top_p","top_k")):
        issues.append("Remove inherited sampling fields for the minimal profile; non-default values are rejected")
    choice=body.get("tool_choice",{})
    if isinstance(choice,dict) and choice.get("type") in ("any","tool"):
        issues.append("Forced tool choice is not accepted; auto does not guarantee a call")
    if "output_format" in body:
        issues.append("Review legacy raw output_format; prefer output_config.format (not an SDK helper rename)")
    messages=body.get("messages")
    if not isinstance(messages,list) or not messages or not all(isinstance(x,dict) for x in messages):
        issues.append("Expected a nonempty messages list of objects")
    else:
        if messages[-1].get("role") == "assistant":
            issues.append("Last assistant prefill is not supported")
        if typ == "between_tools":
            for msg in messages:
                config=msg.get("output_config",{})
                if isinstance(config,dict) and config.get("effort",effort) != effort:
                    issues.append("between_tools cannot vary effort mid-conversation");break
    return issues

def main():
    p=argparse.ArgumentParser(description=__doc__);p.add_argument("request")
    args=p.parse_args()
    try:
        issues=check_request(json.loads(Path(args.request).read_text(encoding="utf-8")))
    except (OSError,ValueError):
        print("Could not read a JSON request");return 2
    print(json.dumps({"local_check_only":True,"items_to_review":issues},indent=2))
    return 1 if issues else 0

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