{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vetrade.vet/schemas/limit-order-plan-response.schema.json",
  "title": "Limit Order Plan Response",
  "oneOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["apiVersion", "requestId", "action", "source", "order", "bundle", "warnings"],
      "properties": {
        "apiVersion": {
          "type": "string",
          "const": "v2"
        },
        "requestId": {
          "type": "string"
        },
        "action": {
          "type": "string",
          "const": "create"
        },
        "source": {
          "type": "string",
          "const": "on_chain"
        },
        "order": {
          "type": "object",
          "additionalProperties": false,
          "required": ["maker", "inputToken", "outputToken", "amountIn", "resolved"],
          "properties": {
            "maker": { "type": "string" },
            "inputToken": { "type": "string" },
            "outputToken": { "type": "string" },
            "amountIn": { "type": "string" },
            "targetPrice": { "type": "string" },
            "minAmountOut": { "type": "string" },
            "resolved": {
              "type": "object",
              "additionalProperties": false,
              "required": ["targetPrice", "onChainPrice", "minAmountOut", "wrapsNativeInput", "vvetUnwrapOnCancel"],
              "properties": {
                "targetPrice": { "type": "string" },
                "onChainPrice": { "type": "string" },
                "minAmountOut": { "type": "string" },
                "wrapsNativeInput": { "type": "boolean" },
                "vvetUnwrapOnCancel": { "type": "boolean" }
              }
            }
          }
        },
        "bundle": {
          "$ref": "#/$defs/bundle"
        },
        "warnings": {
          "$ref": "#/$defs/warnings"
        }
      }
    },
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["apiVersion", "requestId", "action", "source", "cancellation", "bundle", "warnings"],
      "properties": {
        "apiVersion": {
          "type": "string",
          "const": "v2"
        },
        "requestId": {
          "type": "string"
        },
        "action": {
          "type": "string",
          "const": "cancel"
        },
        "source": {
          "type": "string",
          "const": "on_chain"
        },
        "cancellation": {
          "type": "object",
          "additionalProperties": false,
          "required": ["maker", "orderId", "mode", "unwrapVvetOnCancel", "unwrappedAmount", "remainingAmount", "inputToken", "outputToken", "options"],
          "properties": {
            "maker": { "type": "string" },
            "orderId": { "type": "string" },
            "mode": {
              "type": "string",
              "enum": ["cancel_only", "cancel_with_unwrap"]
            },
            "unwrapVvetOnCancel": { "type": "boolean" },
            "unwrappedAmount": { "type": "string" },
            "remainingAmount": { "type": "string" },
            "inputToken": { "type": "string" },
            "outputToken": { "type": "string" },
            "options": {
              "type": "object",
              "additionalProperties": false,
              "required": ["vvetUnwrap"],
              "properties": {
                "vvetUnwrap": { "type": "boolean" }
              }
            }
          }
        },
        "bundle": {
          "$ref": "#/$defs/bundle"
        },
        "warnings": {
          "$ref": "#/$defs/warnings"
        }
      }
    }
  ],
  "$defs": {
    "bundle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["transport", "signer", "allowanceRequirements", "rawClauses", "decodedCalls"],
      "properties": {
        "transport": {
          "type": "string",
          "const": "vechain-clauses"
        },
        "signer": { "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",
                  "wrapped_vet_deposit",
                  "wrapped_vet_withdraw",
                  "limit_order_create",
                  "limit_order_create_with_options",
                  "limit_order_cancel",
                  "contract_call"
                ]
              },
              "to": { "type": "string" },
              "value": { "type": "string" },
              "functionName": { "type": "string" },
              "summary": { "type": "string" },
              "args": { "type": "object" }
            }
          }
        }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "enum": ["ON_CHAIN_LIST_FALLBACK"]
          },
          "message": { "type": "string" }
        }
      }
    }
  }
}
