openapi: 3.0.3
info:
  title: Repzo API - Settlement
  version: 1.0.0
  description: OpenAPI specification for Repzo Settlement endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /settlement:
    get:
      summary: Find settlements
      operationId: findSettlements
      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, completed, cancelled]
              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, totalAmount]
                    type:
                      type: string
                      enum: [asc, desc]
          description: Query parameters for filtering settlements
      responses:
        "200":
          description: A list of settlements
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SettlementFindResult"
    post:
      summary: Create a settlement
      operationId: createSettlement
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SettlementCreateBody"
      responses:
        "201":
          description: Settlement created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SettlementCreateResult"
  /settlement/{id}:
    get:
      summary: Get a settlement by ID
      operationId: getSettlement
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Settlement details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SettlementGetResult"
components:
  schemas:
    SettlementFindResult:
      type: object
      description: Result of finding settlements
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/SettlementSchema"
        total_result:
          type: number
          description: Total number of settlements
        current_count:
          type: number
          description: Count of settlements 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 settlements per page
    SettlementSchema:
      type: object
      description: Settlement schema
      properties:
        _id:
          type: string
          description: Unique identifier for the settlement
        client:
          type: string
          description: Client ID associated with the settlement
        rep:
          type: string
          description: Representative ID who processed the settlement
        invoices:
          type: array
          items:
            type: object
            properties:
              invoice:
                type: string
                description: Invoice ID
              amount:
                type: number
                description: Amount from this invoice
          description: List of invoices included in settlement
        payments:
          type: array
          items:
            type: object
            properties:
              payment:
                type: string
                description: Payment ID
              amount:
                type: number
                description: Payment amount
          description: List of payments included in settlement
        totalAmount:
          type: number
          description: Total settlement amount
        status:
          type: string
          enum: [pending, completed, cancelled]
          description: Status of the settlement
        settlementDate:
          type: string
          format: date-time
          description: Date when settlement was completed
        notes:
          type: string
          description: Additional notes
        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
    SettlementCreateBody:
      type: object
      description: Body for creating a settlement
      required:
        - client
        - invoices
        - payments
      properties:
        client:
          type: string
          description: Client ID associated with the settlement
        rep:
          type: string
          description: Representative ID who processed the settlement
        invoices:
          type: array
          items:
            type: object
            properties:
              invoice:
                type: string
                description: Invoice ID
              amount:
                type: number
                description: Amount from this invoice
          description: List of invoices included in settlement
        payments:
          type: array
          items:
            type: object
            properties:
              payment:
                type: string
                description: Payment ID
              amount:
                type: number
                description: Payment amount
          description: List of payments included in settlement
        notes:
          type: string
          description: Additional notes
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
    SettlementCreateResult:
      $ref: "#/components/schemas/SettlementSchema"
      description: Result of creating a settlement
    SettlementGetResult:
      $ref: "#/components/schemas/SettlementSchema"
      description: Result of getting a settlement
