{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vetrade.vet/schemas/swap-plan-response.schema.json",
  "title": "Swap Plan Response",
  "type": "object",
  "additionalProperties": false,
  "required": ["apiVersion", "requestId", "mode", "quote", "routePlan", "bundle", "simulation", "warnings"],
  "properties": {
    "apiVersion": {
      "type": "string",
      "const": "v2"
    },
    "requestId": {
      "type": "string"
    },
    "mode": {
      "type": "string",
      "enum": ["quote_only", "wallet_bound"]
    },
    "quote": {
      "type": "object",
      "additionalProperties": false,
      "required": ["inputToken", "outputToken", "amountIn", "amountOut", "amountOutMin", "slippageBps", "source", "generatedAt", "validUntil", "validityWindowSeconds", "economicsHint"],
      "properties": {
        "inputToken": { "type": "string" },
        "outputToken": { "type": "string" },
        "amountIn": { "type": "string" },
        "amountOut": { "type": "string" },
        "amountOutMin": { "type": "string" },
        "slippageBps": { "type": "integer" },
        "source": { "type": "string" },
        "generatedAt": { "type": "string", "format": "date-time" },
        "validUntil": { "type": "string", "format": "date-time" },
        "validityWindowSeconds": { "type": "integer" },
        "economicsHint": { "type": "string" }
      }
    },
    "routePlan": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "routes", "instructions", "summary"],
      "properties": {
        "path": {
          "type": "array",
          "items": { "type": "string" }
        },
        "routes": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["path", "pools", "amountIn", "amountOut", "hops"],
            "properties": {
              "path": {
                "type": "array",
                "items": { "type": "string" }
              },
              "pools": {
                "type": "array",
                "items": { "type": "string" }
              },
              "factories": {
                "type": "array",
                "items": { "type": "string" }
              },
              "amountIn": { "type": "string" },
              "amountOut": { "type": "string" },
              "intermediateOutputs": {
                "type": "array",
                "items": { "type": "string" }
              },
              "hops": { "type": "integer" },
              "vetConversions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["from", "to"],
                  "properties": {
                    "from": { "type": "string" },
                    "to": { "type": "string" }
                  }
                }
              }
            }
          }
        },
        "instructions": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["actionType", "router", "path", "amountIn", "amountOutOrMin"],
            "properties": {
              "actionType": { "type": "integer" },
              "actionTypeName": { "type": "string" },
              "router": { "type": "string" },
              "path": {
                "type": "array",
                "items": { "type": "string" }
              },
              "amountIn": { "type": "string" },
              "amountOutOrMin": { "type": "string" },
              "factory": { "type": "string" }
            }
          }
        },
        "summary": {
          "type": "object",
          "additionalProperties": false,
          "required": ["routeCount", "hopCount", "unwrapsToNative", "factories", "instructionTypes", "path", "symbolPath", "routeLabel", "executionPath", "symbolExecutionPath", "addressExecutionPath"],
          "properties": {
            "routeCount": { "type": "integer" },
            "hopCount": { "type": "integer" },
            "unwrapsToNative": { "type": "boolean" },
            "factories": {
              "type": "array",
              "items": { "type": "string" }
            },
            "instructionTypes": {
              "type": "array",
              "items": { "type": "string" }
            },
            "path": {
              "type": "array",
              "items": { "type": "string" }
            },
            "symbolPath": {
              "type": "array",
              "items": { "type": "string" }
            },
            "routeLabel": { "type": "string" },
            "executionPath": { "type": "string" },
            "symbolExecutionPath": { "type": "string" },
            "addressExecutionPath": { "type": "string" }
          }
        }
      }
    },
    "bundle": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["transport", "recipient", "executionContract", "allowanceRequirements", "rawClauses", "decodedCalls"],
          "properties": {
            "transport": {
              "type": "string",
              "const": "vechain-clauses"
            },
            "recipient": { "type": "string" },
            "executionContract": {
              "type": "object",
              "additionalProperties": false,
              "required": ["type", "address"],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": ["ve_aggregate_public", "ve_aggregate2", "unknown"]
                },
                "address": { "type": "string" }
              }
            },
            "allowanceRequirements": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["token", "spender", "amount", "sourceClauseIndex"],
                "properties": {
                  "token": { "type": "string" },
                  "spender": { "type": "string" },
                  "amount": { "type": "string" },
                  "sourceClauseIndex": { "type": "integer" }
                }
              }
            },
            "rawClauses": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["to", "value", "data"],
                "properties": {
                  "to": { "type": "string" },
                  "value": { "type": "string" },
                  "data": { "type": "string" },
                  "comment": { "type": "string" }
                }
              }
            },
            "decodedCalls": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["kind", "to", "value", "functionName", "summary", "args"],
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": ["approval", "swap_execute_public", "swap_execute_router", "contract_call"]
                  },
                  "to": { "type": "string" },
                  "value": { "type": "string" },
                  "functionName": { "type": "string" },
                  "summary": { "type": "string" },
                  "args": { "type": "object" }
                }
              }
            }
          }
        }
      ]
    },
    "simulation": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "properties": {
            "success": { "type": "boolean" },
            "status": { "type": "integer" },
            "statusText": { "type": "string" },
            "transfers": { "type": "object" },
            "errors": { "type": "array" },
            "error": { "type": "string" }
          },
          "required": ["success"],
          "additionalProperties": true
        }
      ]
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "enum": ["SIMULATION_SKIPPED", "BUNDLE_NOT_REQUESTED", "MISSING_ROUTING_INSIGHT"]
          },
          "message": { "type": "string" }
        }
      }
    }
  }
}
