{
  "openapi": "3.1.0",
  "info": {
    "title": "Close Edge v1.1",
    "version": "1.1.0"
  },
  "paths": {
    "/health": {
      "get": {
        "responses": {
          "200": {
            "description": "Health",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/preflight/{venue}/{market_id}": {
      "get": {
        "parameters": [
          {
            "$ref": "#/components/parameters/Venue"
          },
          {
            "$ref": "#/components/parameters/MarketId"
          }
        ],
        "responses": {
          "200": {
            "description": "Preflight",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreflightResponse"
                }
              }
            }
          },
          "404": {
            "description": "Venue or market not found"
          }
        }
      }
    },
    "/v1/resolution-risk/{venue}/{market_id}": {
      "get": {
        "parameters": [
          {
            "$ref": "#/components/parameters/Venue"
          },
          {
            "$ref": "#/components/parameters/MarketId"
          }
        ],
        "responses": {
          "200": {
            "description": "Resolution risk",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResolutionRiskResponse"
                }
              }
            }
          },
          "404": {
            "description": "Venue or market not found"
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "Venue": {
        "name": "venue",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "polymarket",
            "kalshi"
          ]
        }
      },
      "MarketId": {
        "name": "market_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "schemas": {
      "Verdict": {
        "type": "string",
        "enum": [
          "READY",
          "DO_NOT_ACT",
          "INSUFFICIENT_EVIDENCE"
        ]
      },
      "NoTradeReason": {
        "type": "object",
        "required": [
          "class",
          "code",
          "message",
          "advisory"
        ],
        "properties": {
          "class": {
            "type": "string",
            "enum": [
              "R1_WALLET_BINDING",
              "R2_ALLOWANCE_BALANCE",
              "R3_TICK_PRECISION",
              "R4_METADATA_READINESS",
              "R5_MARKET_STATE",
              "R6_BOOK_STALENESS_LIQUIDITY",
              "R7_VENUE_MODE",
              "R8_RESOLUTION_AMBIGUITY"
            ]
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "advisory": {
            "type": "boolean"
          }
        },
        "additionalProperties": false
      },
      "BaseDiagnosticResponse": {
        "type": "object",
        "required": [
          "schema_version",
          "venue",
          "market_id",
          "as_of",
          "verdict",
          "checks_evaluated",
          "no_trade_reasons",
          "what_would_change_this",
          "notes",
          "not_advice"
        ],
        "properties": {
          "schema_version": {
            "type": "string"
          },
          "venue": {
            "type": "string",
            "enum": [
              "polymarket",
              "kalshi"
            ]
          },
          "market_id": {
            "type": "string"
          },
          "as_of": {
            "type": "string"
          },
          "verdict": {
            "$ref": "#/components/schemas/Verdict"
          },
          "checks_evaluated": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "no_trade_reasons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/NoTradeReason"
            }
          },
          "what_would_change_this": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "notes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "not_advice": {
            "type": "boolean"
          }
        },
        "additionalProperties": true
      },
      "PreflightResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDiagnosticResponse"
          },
          {
            "type": "object",
            "required": [
              "wallet_binding_risk",
              "venue_rule_changes_recent"
            ],
            "properties": {
              "wallet_binding_risk": {
                "type": [
                  "object",
                  "null"
                ]
              },
              "venue_rule_changes_recent": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          }
        ]
      },
      "ResolutionRiskResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDiagnosticResponse"
          },
          {
            "type": "object",
            "required": [
              "resolution"
            ],
            "properties": {
              "resolution": {
                "type": "object",
                "required": [
                  "rule_text",
                  "resolution_source",
                  "resolution_mechanism",
                  "ambiguity_flags",
                  "dispute_risk"
                ],
                "properties": {
                  "rule_text": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "resolution_source": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "resolution_mechanism": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "ambiguity_flags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "dispute_risk": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        ]
      },
      "HealthResponse": {
        "type": "object",
        "required": [
          "status",
          "service",
          "version",
          "as_of"
        ],
        "properties": {
          "status": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "as_of": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    }
  }
}
