openapi: 3.0.3
info:
  title: Repzo API - Refund
  version: 1.0.0
  description: OpenAPI specification for Repzo Refund endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /refund:
    get:
      summary: Find refunds
      operationId: findRefunds
      parameters:
        - in: query
          name: params
          schema:
            type: object
            properties:
              _id:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              search:
                type: string
              client:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              rep:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              status:
                type: string
                enum: [pending, approved, rejected, processed]
              from_date:
                type: string
                format: date-time
              to_date:
                type: string
                format: date-time
              from_updatedAt:
                type: number
              from__id:
                type: string
              to__id:
                type: string
              sortBy:
                type: array
                items:
                  type: object
                  properties:
                    field:
                      type: string
                      enum: [_id, createdAt, updatedAt, amount]
                    type:
                      type: string
                      enum: [asc, desc]
          description: Query parameters for filtering refunds
      responses:
        "200":
          description: A list of refunds
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RefundFindResult"
    post:
      summary: Create a refund
      operationId: createRefund
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RefundCreateBody"
      responses:
        "201":
          description: Refund created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RefundCreateResult"
  /refund/{id}:
    get:
      summary: Get a refund by ID
      operationId: getRefund
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Refund details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RefundGetResult"
    put:
      summary: Update a refund
      operationId: updateRefund
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RefundUpdateBody"
      responses:
        "200":
          description: Refund updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RefundUpdateResult"
components:
  schemas:
    RefundFindResult:
      type: object
      description: Result of finding refunds
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/RefundSchema"
        total_result:
          type: number
          description: Total number of refunds
        current_count:
          type: number
          description: Count of refunds in current page
        total_pages:
          type: number
          description: Total number of pages
        current_page:
          type: number
          description: Current page number
        per_page:
          type: number
          description: Number of refunds per page
    RefundSchema:
      type: object
      description: Refund schema
      properties:
        _id:
          type: string
          description: Unique identifier for the refund
        client:
          type: string
          description: Client ID associated with the refund
        rep:
          type: string
          description: Representative ID who processed the refund
        invoice:
          type: string
          description: Invoice ID being refunded
        amount:
          type: number
          description: Refund amount
        reason:
          type: string
          description: Reason for the refund
        status:
          type: string
          enum: [pending, approved, rejected, processed]
          description: Status of the refund
        refundMethod:
          type: string
          description: Method of refund
        reference:
          type: string
          description: Reference number for the refund
        notes:
          type: string
          description: Additional notes
        processedAt:
          type: string
          format: date-time
          description: When the refund was processed
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
        __v:
          type: number
          description: Version number
    RefundCreateBody:
      type: object
      description: Body for creating a refund
      required:
        - client
        - amount
        - reason
      properties:
        client:
          type: string
          description: Client ID associated with the refund
        rep:
          type: string
          description: Representative ID who processed the refund
        invoice:
          type: string
          description: Invoice ID being refunded
        amount:
          type: number
          description: Refund amount
        reason:
          type: string
          description: Reason for the refund
        refundMethod:
          type: string
          description: Method of refund
        reference:
          type: string
          description: Reference number for the refund
        notes:
          type: string
          description: Additional notes
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
    RefundCreateResult:
      $ref: "#/components/schemas/RefundSchema"
      description: Result of creating a refund
    RefundGetResult:
      $ref: "#/components/schemas/RefundSchema"
      description: Result of getting a refund
    RefundUpdateBody:
      type: object
      description: Body for updating a refund
      properties:
        status:
          type: string
          enum: [pending, approved, rejected, processed]
          description: Status of the refund
        refundMethod:
          type: string
          description: Method of refund
        reference:
          type: string
          description: Reference number for the refund
        notes:
          type: string
          description: Additional notes
        processedAt:
          type: string
          format: date-time
          description: When the refund was processed
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
    RefundUpdateResult:
      $ref: "#/components/schemas/RefundSchema"
      description: Result of updating a refund
