{
  "components": {
    "schemas": {
      "CreateWebhookSubscriptionRequest": {
        "additionalProperties": false,
        "properties": {
          "description": {
            "nullable": true,
            "type": "string"
          },
          "eventTypes": {
            "items": {
              "type": "string"
            },
            "nullable": true,
            "type": "array"
          },
          "secretKey": {
            "nullable": true,
            "type": "string"
          },
          "webhookUrl": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "CreateWebhookSubscriptionResponse": {
        "additionalProperties": false,
        "properties": {
          "createdAt": {
            "format": "date-time",
            "type": "string"
          },
          "status": {
            "nullable": true,
            "type": "string"
          },
          "subscriptionId": {
            "format": "uuid",
            "type": "string"
          }
        },
        "type": "object"
      },
      "DeliveryStatisticsDto": {
        "additionalProperties": false,
        "properties": {
          "averageDurationMs": {
            "format": "double",
            "type": "number"
          },
          "failedDeliveries": {
            "format": "int32",
            "type": "integer"
          },
          "pendingDeliveries": {
            "format": "int32",
            "type": "integer"
          },
          "successRate": {
            "format": "double",
            "type": "number"
          },
          "successfulDeliveries": {
            "format": "int32",
            "type": "integer"
          },
          "totalDeliveries": {
            "format": "int32",
            "type": "integer"
          }
        },
        "type": "object"
      },
      "ProblemDetails": {
        "additionalProperties": {},
        "properties": {
          "detail": {
            "nullable": true,
            "type": "string"
          },
          "instance": {
            "nullable": true,
            "type": "string"
          },
          "status": {
            "format": "int32",
            "nullable": true,
            "type": "integer"
          },
          "title": {
            "nullable": true,
            "type": "string"
          },
          "type": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "RedriveWebhookDeliveriesRequest": {
        "additionalProperties": false,
        "properties": {
          "deliveryIds": {
            "items": {
              "format": "uuid",
              "type": "string"
            },
            "nullable": true,
            "type": "array"
          },
          "maxBatchSize": {
            "format": "int32",
            "nullable": true,
            "type": "integer"
          }
        },
        "type": "object"
      },
      "RedriveWebhookDeliveriesResponse": {
        "additionalProperties": false,
        "properties": {
          "moreAvailable": {
            "type": "boolean"
          },
          "redriven": {
            "items": {
              "$ref": "#/components/schemas/RedrivenDelivery"
            },
            "nullable": true,
            "type": "array"
          },
          "redrivenAt": {
            "format": "date-time",
            "type": "string"
          },
          "redrivenCount": {
            "format": "int32",
            "type": "integer"
          },
          "skipped": {
            "items": {
              "$ref": "#/components/schemas/SkippedDelivery"
            },
            "nullable": true,
            "type": "array"
          },
          "subscriptionId": {
            "format": "uuid",
            "type": "string"
          }
        },
        "type": "object"
      },
      "RedrivenDelivery": {
        "additionalProperties": false,
        "properties": {
          "eventType": {
            "nullable": true,
            "type": "string"
          },
          "originalDeliveryId": {
            "format": "uuid",
            "type": "string"
          },
          "replacementDeliveryId": {
            "format": "uuid",
            "type": "string"
          }
        },
        "type": "object"
      },
      "RotateWebhookSecretRequest": {
        "additionalProperties": false,
        "properties": {
          "overlapHours": {
            "format": "int32",
            "nullable": true,
            "type": "integer"
          }
        },
        "type": "object"
      },
      "RotateWebhookSecretResponse": {
        "additionalProperties": false,
        "properties": {
          "newSecret": {
            "nullable": true,
            "type": "string"
          },
          "previousSecretExpiresAt": {
            "format": "date-time",
            "type": "string"
          },
          "rotatedAt": {
            "format": "date-time",
            "type": "string"
          },
          "subscriptionId": {
            "format": "uuid",
            "type": "string"
          }
        },
        "type": "object"
      },
      "SkippedDelivery": {
        "additionalProperties": false,
        "properties": {
          "deliveryId": {
            "format": "uuid",
            "type": "string"
          },
          "reason": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "TriggerWebhookEventRequest": {
        "additionalProperties": false,
        "properties": {
          "eventType": {
            "nullable": true,
            "type": "string"
          },
          "payload": {
            "nullable": true,
            "type": "string"
          },
          "source": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "UpdateWebhookSubscriptionRequest": {
        "additionalProperties": false,
        "properties": {
          "description": {
            "nullable": true,
            "type": "string"
          },
          "eventTypes": {
            "items": {
              "type": "string"
            },
            "nullable": true,
            "type": "array"
          },
          "secretKey": {
            "nullable": true,
            "type": "string"
          },
          "webhookUrl": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "WebhookDeliveryLogDto": {
        "additionalProperties": false,
        "properties": {
          "attemptNumber": {
            "format": "int32",
            "type": "integer"
          },
          "canRedrive": {
            "type": "boolean"
          },
          "createdAt": {
            "format": "date-time",
            "type": "string"
          },
          "deliveredAt": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "durationMs": {
            "format": "int64",
            "nullable": true,
            "type": "integer"
          },
          "errorMessage": {
            "nullable": true,
            "type": "string"
          },
          "eventType": {
            "nullable": true,
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "nextRetryAt": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "payload": {
            "nullable": true,
            "type": "string"
          },
          "redriveOfDeliveryId": {
            "format": "uuid",
            "nullable": true,
            "type": "string"
          },
          "redrivenAt": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "responseBody": {
            "nullable": true,
            "type": "string"
          },
          "status": {
            "nullable": true,
            "type": "string"
          },
          "statusCode": {
            "format": "int32",
            "nullable": true,
            "type": "integer"
          },
          "subscriptionId": {
            "format": "uuid",
            "type": "string"
          },
          "updatedAt": {
            "format": "date-time",
            "type": "string"
          },
          "webhookUrl": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "WebhookSubscriptionDto": {
        "additionalProperties": false,
        "properties": {
          "createdAt": {
            "format": "date-time",
            "type": "string"
          },
          "description": {
            "nullable": true,
            "type": "string"
          },
          "eventTypes": {
            "items": {
              "type": "string"
            },
            "nullable": true,
            "type": "array"
          },
          "failureCount": {
            "format": "int32",
            "type": "integer"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "lastFailureAt": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "lastSuccessAt": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "partnerId": {
            "format": "uuid",
            "type": "string"
          },
          "status": {
            "nullable": true,
            "type": "string"
          },
          "updatedAt": {
            "format": "date-time",
            "type": "string"
          },
          "webhookUrl": {
            "nullable": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "WebhookSubscriptionDtoPaginatedResponse": {
        "additionalProperties": false,
        "properties": {
          "hasNextPage": {
            "readOnly": true,
            "type": "boolean"
          },
          "hasPreviousPage": {
            "readOnly": true,
            "type": "boolean"
          },
          "items": {
            "items": {
              "$ref": "#/components/schemas/WebhookSubscriptionDto"
            },
            "nullable": true,
            "type": "array"
          },
          "pageNumber": {
            "format": "int32",
            "type": "integer"
          },
          "pageSize": {
            "format": "int32",
            "type": "integer"
          },
          "totalCount": {
            "format": "int32",
            "type": "integer"
          },
          "totalPages": {
            "format": "int32",
            "readOnly": true,
            "type": "integer"
          }
        },
        "type": "object"
      }
    },
    "securitySchemes": {
      "Bearer": {
        "description": "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
        "in": "header",
        "name": "Authorization",
        "type": "apiKey"
      }
    }
  },
  "info": {
    "contact": {
      "email": "support@essence.digital",
      "name": "Essence Platform",
      "url": "https://essence.digital"
    },
    "description": "Unified webhook management platform for partner integrations",
    "title": "Essence Webhook Management API",
    "version": "v1"
  },
  "openapi": "3.0.1",
  "paths": {
    "/api/v1/webhooks": {
      "get": {
        "parameters": [
          {
            "in": "query",
            "name": "pageNumber",
            "schema": {
              "default": 1,
              "format": "int32",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "pageSize",
            "schema": {
              "default": 20,
              "format": "int32",
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookSubscriptionDtoPaginatedResponse"
                }
              }
            },
            "description": "Success"
          }
        },
        "summary": "Gets all webhook subscriptions with pagination",
        "tags": [
          "Webhooks"
        ]
      },
      "post": {
        "requestBody": {
          "content": {
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookSubscriptionRequest"
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookSubscriptionRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookSubscriptionRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateWebhookSubscriptionResponse"
                }
              }
            },
            "description": "Created"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Bad Request"
          }
        },
        "summary": "Creates a new webhook subscription",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/events": {
      "post": {
        "requestBody": {
          "content": {
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/TriggerWebhookEventRequest"
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TriggerWebhookEventRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/TriggerWebhookEventRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "content": {
              "application/json": {
                "schema": {
                  "format": "int32",
                  "type": "integer"
                }
              }
            },
            "description": "Accepted"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Bad Request"
          }
        },
        "summary": "Triggers webhook delivery for an event (internal API)",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}": {
      "delete": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Deletes a webhook subscription",
        "tags": [
          "Webhooks"
        ]
      },
      "get": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookSubscriptionDto"
                }
              }
            },
            "description": "Success"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Gets a webhook subscription by ID",
        "tags": [
          "Webhooks"
        ]
      },
      "put": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWebhookSubscriptionRequest"
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWebhookSubscriptionRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWebhookSubscriptionRequest"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "No Content"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Updates a webhook subscription",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/deliveries": {
      "get": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "pageNumber",
            "schema": {
              "default": 1,
              "format": "int32",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "pageSize",
            "schema": {
              "default": 50,
              "format": "int32",
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/WebhookDeliveryLogDto"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Success"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Gets delivery logs for a webhook subscription",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/deliveries/redrive": {
      "post": {
        "description": "The replays re-enter the normal signing + retry path as NEW delivery attempts; the\r\noriginal dead-lettered rows stay terminal so the record of the failure survives the\r\nrecovery. Send no body (or an empty `deliveryIds`) to replay everything eligible.",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/RedriveWebhookDeliveriesRequest"
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RedriveWebhookDeliveriesRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/RedriveWebhookDeliveriesRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedriveWebhookDeliveriesResponse"
                }
              }
            },
            "description": "Success"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Bad Request"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Re-drives (replays) this subscription's dead-lettered deliveries — FR-08.058,\r\ndebt-2026-08-20-044. Scoped to the caller's OWN subscription and idempotent per\r\ndelivery id: calling twice does not double-deliver, because each dead letter records\r\nthat it has been replayed.",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/rotate-secret": {
      "post": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/RotateWebhookSecretRequest"
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RotateWebhookSecretRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/RotateWebhookSecretRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RotateWebhookSecretResponse"
                }
              }
            },
            "description": "Success"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Bad Request"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Rotates the webhook's signing secret (FR-08.045). Generates a fresh secret and\r\nkeeps the previous one valid for an overlap window (default 24h, max 7 days) so\r\nreceivers can redeploy without dropping deliveries. The new secret is returned\r\nONCE in the response and is never retrievable again.",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/statistics": {
      "get": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "fromDate",
            "schema": {
              "format": "date-time",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "toDate",
            "schema": {
              "format": "date-time",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryStatisticsDto"
                }
              }
            },
            "description": "Success"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Gets delivery statistics for a webhook subscription",
        "tags": [
          "Webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/test": {
      "post": {
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Not Found"
          }
        },
        "summary": "Sends a test webhook (for testing purposes)",
        "tags": [
          "Webhooks"
        ]
      }
    }
  },
  "security": [
    {
      "Bearer": []
    }
  ]
}
