{
  "openapi": "3.0.0",
  "info": {
    "version": "v1.0.0",
    "title": "Webhooks API",
    "description": "API for managing webhooks in the Rio platform"
  },
  "servers": [
    {
      "url": "https://app.sandbox.rio.trade"
    }
  ],
  "paths": {
    "/api/webhooks/{id}": {
      "get": {
        "summary": "Get a webhook registration",
        "description": "",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Id of the webhook to be obtained."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/responseWebhookSchema"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Update a webhook registration",
        "description": "",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Id of the webhook to be updated."
          }
        ],
        "responses": {
          "204": {
            "description": "Webhook updated successfully"
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/updateWebHookSchema"
              }
            }
          },
          "required": true
        }
      },
      "delete": {
        "description": "",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Id of the webhook to delete."
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          }
        }
      }
    },
    "/api/webhooks": {
      "get": {
        "summary": "Get all webhook registrations",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/userIdQueryParameter"
          },
          {
            "$ref": "#/components/parameters/pageQueryParameter"
          },
          {
            "$ref": "#/components/parameters/limitQueryParameter"
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/responseAllWebhooksSchema"
                }
              }
            },
            "description": "OK"
          }
        }
      }
    },
    "/api/webhooks/{type}": {
      "post": {
        "summary": "Create a webhook registration",
        "description": "",
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/webhookTypePathParameter"
          }
        ],
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/responseCreatedWebhookSchema"
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/createWebHookSchema"
              }
            }
          },
          "required": true
        }
      }
    }
  },
  "components": {
    "schemas": {
      "unauthorizedSchema": {
        "type": "object",
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "number",
                  "example": 19
                },
                "message": {
                  "type": "string",
                  "example": "Not authorized"
                }
              }
            }
          }
        }
      },
      "notFound": {
        "type": "object",
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "number",
                  "example": 21
                },
                "message": {
                  "type": "string",
                  "example": "Quote not found"
                }
              }
            }
          }
        }
      },
      "createWebHookSchema": {
        "type": "object",
        "properties": {
          "userId": {
            "description": "The user ID of the user that the webhook is being created for",
            "type": "string",
            "example": "66290ac8bd3903485989f82e"
          },
          "url": {
            "type": "string",
            "description": "URL to send the webhook to"
          },
          "retryOnFailure": {
            "type": "boolean",
            "description": "Whether to retry webhook delivery on failure. If true, the system will retry up to 5 times with exponential backoff. If false or not provided, only one attempt will be made.",
            "example": true
          }
        },
        "required": [
          "url"
        ]
      },
      "updateWebHookSchema": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "URL to send the webhook to"
          },
          "retryOnFailure": {
            "type": "boolean",
            "description": "Whether to retry webhook delivery on failure. If true, the system will retry up to 5 times with exponential backoff. If false, only one attempt will be made.",
            "example": true
          }
        }
      },
      "responseAllWebhooksSchema": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "userId": {
              "type": "string",
              "description": "Id of the user that the webhook is for",
              "example": "66562bc04fe8bf83c577c178"
            },
            "type": {
              "type": "string",
              "description": "Type of webhook",
              "enum": [
                "orders",
                "bank-accounts",
                "users"
              ]
            },
            "url": {
              "type": "string",
              "description": "URL to send the webhook to",
              "example": "https://app.test.rio.trade/en/account"
            },
            "id": {
              "type": "string",
              "description": "Id of the webhook registration",
              "example": "66733d33222710ab2785dc62"
            },
            "retryOnFailure": {
              "type": "boolean",
              "description": "Whether the webhook will retry on failure",
              "example": true
            }
          }
        }
      },
      "responseCreatedWebhookSchema": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Id of the created webhook",
            "example": "66733d33222710ab2785dc62"
          },
          "secret": {
            "description": "Webhook secret",
            "type": "string",
            "example": "IgAeeIIorKQ86gAGItsmY0slzhxRY1Gvj/VIJz8DtIs="
          }
        }
      },
      "responseWebhookSchema": {
        "type": "object",
        "properties": {
          "userId": {
            "type": "string",
            "description": "Id of the user that the webhook is for",
            "example": "66562bc04fe8bf83c577c178"
          },
          "type": {
            "type": "string",
            "description": "Type of webhook",
            "enum": [
              "orders",
              "bank-accounts",
              "users"
            ]
          },
          "url": {
            "type": "string",
            "description": "URL to send the webhook to",
            "example": "https://app.test.rio.trade/en/account"
          },
          "id": {
            "type": "string",
            "description": "Id of the webhook registration",
            "example": "66733d33222710ab2785dc62"
          },
          "retryOnFailure": {
            "type": "boolean",
            "description": "Whether the webhook will retry on failure",
            "example": true
          }
        }
      }
    },
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "parameters": {
      "pageQueryParameter": {
        "name": "page",
        "in": "query",
        "description": "Used to specify the current page you want to get in the paging results.",
        "schema": {
          "type": "integer"
        }
      },
      "limitQueryParameter": {
        "name": "limit",
        "in": "query",
        "description": "Used to specify the maximum number of records to be returned on a single page.",
        "schema": {
          "type": "integer"
        }
      },
      "userIdQueryParameter": {
        "name": "userId",
        "in": "query",
        "description": "User id to filter the results.",
        "example": "66562bc04fe8bf83c577c178",
        "schema": {
          "type": "string"
        }
      },
      "webhookTypePathParameter": {
        "name": "type",
        "in": "path",
        "description": "Type of webhook to be created.",
        "required": true,
        "schema": {
          "enum": [
            "orders",
            "bank-accounts",
            "users"
          ]
        }
      }
    }
  },
  "security": [
    {
      "apiKeyAuth": []
    }
  ]
}