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
              "creator._id":
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              "origin._id":
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              creator:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              origin:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              "creator.type":
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              "origin.type":
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              creator_type:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              origin_type:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              amount:
                type: number
              payment_type:
                type: string
              from_createdAt:
                type: number
              to_createdAt:
                type: number
              from_updatedAt:
                type: number
              from__id:
                type: string
              to__id:
                type: string
              sortBy:
                type: array
                items:
                  type: object
                  properties:
                    field:
                      type: string
                      enum: [_id]
                    type:
                      type: string
                      enum: [asc, desc]
              populatedKeys:
                type: array
                items:
                  type: string
                  enum: [teams, check_id, media]
          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
        - in: query
          name: params
          schema:
            type: object
            properties:
              populatedKeys:
                type: array
                items:
                  type: string
                  enum: [teams, check_id, media]
      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/SettlementSchemaWithPopulatedKeys"
        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
        absolute_total:
          type: number
          description: Absolute total count
        page_total:
          type: number
          description: Page total count
    SettlementSchema:
      type: object
      description: Settlement schema
      properties:
        _id:
          type: string
          description: Unique identifier for the settlement
        amount:
          type: number
          description: Settlement amount
        creator:
          type: object
          description: Creator of the settlement
          properties:
            _id:
              type: string
            type:
              type: string
              enum: [admin, rep]
            admin:
              type: string
            rep:
              type: string
            name:
              type: string
        origin:
          type: object
          description: Origin of the settlement
          properties:
            _id:
              type: string
            type:
              type: string
              enum: [rep, admin]
            name:
              type: string
            rep:
              type: string
            admin:
              type: string
        time:
          type: number
          description: Settlement time
        serial_number:
          type: object
          description: Serial number information
          properties:
            identifier:
              type: string
            formatted:
              type: string
            count:
              type: number
        paytime:
          type: string
          description: Payment time
        note:
          type: string
          description: Settlement note
        payment_type:
          type: string
          enum: [check, cash]
          description: Type of payment
        check_id:
          type: string
          description: Check ID if payment type is check
        teams:
          type: array
          items:
            type: string
          description: Associated team IDs
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces
        sync_id:
          type: string
          description: Sync identifier
        transaction_processed:
          type: boolean
          description: Whether transaction has been processed
        media:
          type: array
          items:
            type: string
          description: Media attachment IDs
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
    SettlementSchemaWithPopulatedKeys:
      allOf:
        - $ref: "#/components/schemas/SettlementSchema"
        - type: object
          properties:
            teams_populated:
              oneOf:
                - type: array
                  items:
                    type: string
                - type: array
                  items:
                    $ref: "#/components/schemas/TeamSchema"
            check_populated:
              oneOf:
                - type: string
                - $ref: "#/components/schemas/CheckSchema"
            media_populated:
              oneOf:
                - type: array
                  items:
                    type: string
                - type: array
                  items:
                    $ref: "#/components/schemas/MediaPopulated"
    TeamSchema:
      type: object
      description: Team schema reference
      properties:
        _id:
          type: string
        name:
          type: string
    CheckSchema:
      type: object
      description: Check schema reference
      properties:
        _id:
          type: string
        drawer_name:
          type: string
        bank:
          type: string
        amount:
          type: number
    MediaPopulated:
      type: object
      description: Media populated schema
      properties:
        _id:
          type: string
        media_type:
          type: string
          enum:
            [
              csv,
              json,
              image,
              pdf,
              ppt,
              pptx,
              xls,
              xlsx,
              doc,
              docx,
              images,
              zip,
            ]
        mime_type:
          type: string
        publicUrl:
          type: string
        file_name:
          type: string
        type_name:
          type: string
          enum: [FileAttachment, ImageAttachment]
        media_id:
          type: string
        ContentType:
          type: string
        createdAt:
          type: string
        updatedAt:
          type: string
        thumbnails:
          $ref: "#/components/schemas/ThumbnailStoragePopulated"
    ThumbnailStoragePopulated:
      type: object
      description: Thumbnail storage populated schema
      properties:
        _id:
          type: string
        createdAt:
          type: string
        ContentType:
          type: string
        mime_type:
          type: string
        publicUrl:
          type: string
        type_name:
          type: string
          enum: [FileAttachment, ImageAttachment]
        file_name:
          type: string
        media_id:
          type: string
        media_type:
          type: string
          enum:
            [
              csv,
              json,
              image,
              pdf,
              "ppt",
              pptx,
              xls,
              xlsx,
              doc,
              docx,
              "images",
              zip,
              thumbnail,
            ]
    SettlementCreateBody:
      type: object
      description: Body for creating a settlement
      required:
        - amount
        - origin
        - serial_number
        - paytime
        - payment_type
        - teams
        - company_namespace
        - sync_id
        - transaction_processed
      properties:
        amount:
          type: number
          description: Settlement amount
        time:
          type: number
          description: Settlement time
        creator:
          type: object
          description: Creator of the settlement
          properties:
            _id:
              type: string
            type:
              type: string
              enum: [admin, rep]
            admin:
              type: string
            rep:
              type: string
            name:
              type: string
        origin:
          type: object
          description: Origin of the settlement
          properties:
            _id:
              type: string
            type:
              type: string
              enum: [rep, admin]
            name:
              type: string
            rep:
              type: string
            admin:
              type: string
        serial_number:
          type: object
          description: Serial number information
          properties:
            identifier:
              type: string
            formatted:
              type: string
            count:
              type: number
        paytime:
          type: string
          description: Payment time
        note:
          type: string
          description: Settlement note
        payment_type:
          type: string
          enum: [check, cash]
          description: Type of payment
        check_id:
          type: string
          description: Check ID if payment type is check
        teams:
          type: array
          items:
            type: string
          description: Associated team IDs
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces
        sync_id:
          type: string
          description: Sync identifier
        transaction_processed:
          type: boolean
          description: Whether transaction has been processed
        media:
          type: array
          items:
            type: string
          description: Media attachment IDs
    SettlementCreateResult:
      $ref: "#/components/schemas/SettlementSchema"
      description: Result of creating a settlement
    SettlementGetResult:
      $ref: "#/components/schemas/SettlementSchemaWithPopulatedKeys"
      description: Result of getting a settlement
