openapi: 3.0.0
info:
  title: Svix Integration API
  description: API for managing Svix webhook integrations
  version: 1.0.0
  contact:
    name: Repzo
    url: https://repzo.com

servers:
  - url: https://sv.api.repzo.me
    description: Production server
  - url: https://staging.sv.api.repzo.me
    description: Staging server

tags:
  - name: Svix Integration
    description: Operations related to Svix webhook integration management

paths:
  /svix-integration:
    get:
      tags:
        - Svix Integration
      summary: Get all Svix integration records
      description: Retrieve a list of all Svix integration records with optional filtering and pagination
      parameters:
        - name: limit
          in: query
          description: Maximum number of records to return
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 50
        - name: offset
          in: query
          description: Number of records to skip for pagination
          required: false
          schema:
            type: integer
            minimum: 0
            default: 0
        - name: sort
          in: query
          description: Field to sort by
          required: false
          schema:
            type: string
        - name: order
          in: query
          description: Sort order (asc or desc)
          required: false
          schema:
            type: string
            enum: [asc, desc]
            default: desc
        - name: filter
          in: query
          description: Filter conditions in JSON format
          required: false
          schema:
            type: string
        - name: search
          in: query
          description: Search term for text fields
          required: false
          schema:
            type: string
      responses:
        "200":
          description: List of Svix integration records retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/SvixIntegration"
                  total:
                    type: integer
                    description: Total number of records
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    post:
      tags:
        - Svix Integration
      summary: Create a new Svix integration
      description: Create a new Svix integration with the provided data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SvixIntegrationInput"
      responses:
        "201":
          description: Svix integration created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/SvixIntegration"
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

  /svix-integration/{id}:
    get:
      tags:
        - Svix Integration
      summary: Get Svix integration by ID
      description: Retrieve a specific Svix integration by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Svix integration ID
          schema:
            type: string
      responses:
        "200":
          description: Svix integration retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/SvixIntegration"
        "404":
          description: Svix integration not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    put:
      tags:
        - Svix Integration
      summary: Update Svix integration
      description: Update an existing Svix integration with new data
      parameters:
        - name: id
          in: path
          required: true
          description: Svix integration ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SvixIntegrationInput"
      responses:
        "200":
          description: Svix integration updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/SvixIntegration"
        "400":
          description: Bad request
        "404":
          description: Svix integration not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    delete:
      tags:
        - Svix Integration
      summary: Delete Svix integration
      description: Delete an existing Svix integration
      parameters:
        - name: id
          in: path
          required: true
          description: Svix integration ID
          schema:
            type: string
      responses:
        "200":
          description: Svix integration deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Svix integration deleted successfully
        "404":
          description: Svix integration not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

components:
  schemas:
    SvixIntegration:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the Svix integration
          example: "60f7b1b3e4b0e8b3f8b3f8b3"
        name:
          type: string
          description: Name of the integration
          example: "Webhook Integration"
        description:
          type: string
          description: Description of the integration
        applicationId:
          type: string
          description: Svix application ID
          example: "app_12345"
        endpointUrl:
          type: string
          format: uri
          description: Webhook endpoint URL
          example: "https://example.com/webhook"
        eventTypes:
          type: array
          items:
            type: string
          description: List of event types to subscribe to
          example: ["user.created", "order.updated"]
        secret:
          type: string
          description: Webhook secret for signature verification
        isActive:
          type: boolean
          default: true
          description: Whether the integration is active
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
        createdAt:
          type: string
          format: date-time
          description: Record creation timestamp
          example: "2023-01-15T08:00:00Z"
        updatedAt:
          type: string
          format: date-time
          description: Record last update timestamp
          example: "2023-01-15T10:30:00Z"
      required:
        - name
        - applicationId
        - endpointUrl

    SvixIntegrationInput:
      type: object
      properties:
        name:
          type: string
          description: Name of the integration
          example: "Webhook Integration"
        description:
          type: string
          description: Description of the integration
        applicationId:
          type: string
          description: Svix application ID
          example: "app_12345"
        endpointUrl:
          type: string
          format: uri
          description: Webhook endpoint URL
          example: "https://example.com/webhook"
        eventTypes:
          type: array
          items:
            type: string
          description: List of event types to subscribe to
          example: ["user.created", "order.updated"]
        secret:
          type: string
          description: Webhook secret for signature verification
        isActive:
          type: boolean
          default: true
          description: Whether the integration is active
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
      required:
        - name
        - applicationId
        - endpointUrl

  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: api-key

security:
  - ApiKeyAuth: []
