import requests
import json
from config import Config
from logging_config import setup_logging

logger = setup_logging("ce_parser")

def parse_openapi():
    # Use CE IP directly for this local tool
    url = "http://172.17.0.1:8000/openapi.json"
    auth = (Config.CE_API_USER, Config.CE_API_PASSWORD)
    try:
        resp = requests.get(url, auth=auth, timeout=5)
        resp.raise_for_status()
        spec = resp.json()
        schemas = spec.get("components", {}).get("schemas", {})
        target_schemas = ["CompanyCreate", "BulkImportRequest"]
        for schema_name in target_schemas:
            if schema_name in schemas:
                print(f"\nSchema: {schema_name}")
                print(json.dumps(schemas[schema_name], indent=2))
    except Exception as e:
        logger.error(f"Error parsing CE OpenAPI: {e}")

if __name__ == "__main__":
    parse_openapi()