#!/usr/bin/env python3
"""Inspect a locally downloaded Agora OpenAPI file. No network or writes."""
import json
import sys
from pathlib import Path

if len(sys.argv) != 3:
    raise SystemExit('Usage: python inspect_contract.py openapi.json /pricing/price-lists')
contract = json.loads(Path(sys.argv[1]).read_text())
route = sys.argv[2]
operations = contract.get('paths', {}).get(route)
if not operations:
    raise SystemExit('Route not present in this contract: ' + route)
print('Contract version:', contract.get('info', {}).get('version', 'unspecified'))
for method, operation in operations.items():
    if method not in {'get', 'post', 'put', 'patch', 'delete', 'head', 'options'}:
        continue
    print(method.upper(), route)
    print('  Summary:', operation.get('summary', 'not supplied'))
    print('  Responses:', ', '.join(operation.get('responses', {}).keys()) or 'not supplied')
    print('  Request body:', 'declared' if 'requestBody' in operation else 'not declared')
