paths:
  /merchants/webhooks/outgoing:
    get:
      summary: List outgoing webhook logs
      description: Retrieve a paginated list of webhooks sent from Airpero to the merchant's configured webhook URL.
      tags:
        - Merchant Webhooks
      security:
        - bearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
        - in: query
          name: status
          schema:
            type: string
            enum: [pending, delivered, failed, skipped]
      responses:
        '200':
          description: List of outgoing logs
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/MerchantWebhookLog'
  
  /merchants/webhooks/outgoing/{id}/resend:
    post:
      summary: Resend an outgoing webhook
      description: Manually trigger a redelivery of a previously logged outgoing webhook.
      tags:
        - Merchant Webhooks
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Resend result
  
  /merchants/webhooks/incoming:
    get:
      summary: List incoming 9PSB webhook logs
      description: Retrieve a paginated list of raw webhooks received from 9PSB that are associated with the merchant's account or their customers.
      tags:
        - Merchant Webhooks
      security:
        - bearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
        - in: query
          name: status
          schema:
            type: string
            enum: [received, processed, failed]
      responses:
        '200':
          description: List of incoming logs

  /merchants/webhooks/incoming/{id}/retry:
    post:
      summary: Retry an incoming webhook
      description: |
        Manually trigger the processing of a raw incoming webhook. 
        - If the transaction was already successful, it will only resend the notification to the merchant.
        - If the transaction has not been processed, it will attempt to credit/debit the customer and then notify the merchant.
      tags:
        - Merchant Webhooks
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Retry trigger successful

components:
  schemas:
    MerchantWebhookLog:
      type: object
      properties:
        id:
          type: string
          format: uuid
        event:
          type: string
        webhookUrl:
          type: string
        payload:
          type: object
        status:
          type: string
        response:
          type: string
        attempts:
          type: integer
        createdAt:
          type: string
          format: date-time
