openapi: 3.0.3
info:
  title: Repzo API - Receiving Material
  version: 1.0.0
  description: OpenAPI specification for Repzo Receiving Material endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /receiving-material:
    get:
      summary: Find receiving materials
      operationId: findReceivingMaterials
      parameters:
        - in: query
          name: params
          schema:
            type: object
            properties:
              _id:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              search:
                type: string
              warehouse:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              supplier:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              rep:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              status:
                type: string
                enum: [pending, received, 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, receiptDate]
                    type:
                      type: string
                      enum: [asc, desc]
          description: Query parameters for filtering receiving materials
      responses:
        "200":
          description: A list of receiving materials
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReceivingMaterialFindResult"
    post:
      summary: Create a receiving material
      operationId: createReceivingMaterial
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ReceivingMaterialCreateBody"
      responses:
        "201":
          description: Receiving material created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReceivingMaterialCreateResult"
  /receiving-material/{id}:
    get:
      summary: Get a receiving material by ID
      operationId: getReceivingMaterial
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Receiving material details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReceivingMaterialGetResult"
    put:
      summary: Update a receiving material
      operationId: updateReceivingMaterial
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ReceivingMaterialUpdateBody"
      responses:
        "200":
          description: Receiving material updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReceivingMaterialUpdateResult"
components:
  schemas:
    ReceivingMaterialFindResult:
      type: object
      description: Result of finding receiving materials
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/ReceivingMaterialSchema"
        total_result:
          type: number
          description: Total number of receiving materials
        current_count:
          type: number
          description: Count of receiving materials 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 receiving materials per page
    ReceivingMaterialSchema:
      type: object
      description: Receiving material schema
      properties:
        _id:
          type: string
          description: Unique identifier for the receiving material
        warehouse:
          type: string
          description: Warehouse ID where materials are received
        supplier:
          type: string
          description: Supplier ID providing the materials
        rep:
          type: string
          description: Representative ID who received the materials
        receiptNumber:
          type: string
          description: Receipt number
        receiptDate:
          type: string
          format: date-time
          description: Date when materials were received
        items:
          type: array
          items:
            type: object
            properties:
              product:
                type: string
                description: Product ID
              variant:
                type: string
                description: Product variant ID
              expectedQuantity:
                type: number
                description: Expected quantity to receive
              receivedQuantity:
                type: number
                description: Actually received quantity
              unitCost:
                type: number
                description: Unit cost of the item
              totalCost:
                type: number
                description: Total cost for this item
          description: List of items received
        totalAmount:
          type: number
          description: Total amount of the receipt
        status:
          type: string
          enum: [pending, received, cancelled]
          description: Status of the receiving material
        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
    ReceivingMaterialCreateBody:
      type: object
      description: Body for creating a receiving material
      required:
        - warehouse
        - supplier
        - items
      properties:
        warehouse:
          type: string
          description: Warehouse ID where materials are received
        supplier:
          type: string
          description: Supplier ID providing the materials
        rep:
          type: string
          description: Representative ID who received the materials
        receiptNumber:
          type: string
          description: Receipt number
        receiptDate:
          type: string
          format: date-time
          description: Date when materials were received
        items:
          type: array
          items:
            type: object
            properties:
              product:
                type: string
                description: Product ID
              variant:
                type: string
                description: Product variant ID
              expectedQuantity:
                type: number
                description: Expected quantity to receive
              receivedQuantity:
                type: number
                description: Actually received quantity
              unitCost:
                type: number
                description: Unit cost of the item
          description: List of items received
        notes:
          type: string
          description: Additional notes
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
    ReceivingMaterialCreateResult:
      $ref: "#/components/schemas/ReceivingMaterialSchema"
      description: Result of creating a receiving material
    ReceivingMaterialGetResult:
      $ref: "#/components/schemas/ReceivingMaterialSchema"
      description: Result of getting a receiving material
    ReceivingMaterialUpdateBody:
      type: object
      description: Body for updating a receiving material
      properties:
        receiptDate:
          type: string
          format: date-time
          description: Date when materials were received
        items:
          type: array
          items:
            type: object
            properties:
              product:
                type: string
                description: Product ID
              variant:
                type: string
                description: Product variant ID
              expectedQuantity:
                type: number
                description: Expected quantity to receive
              receivedQuantity:
                type: number
                description: Actually received quantity
              unitCost:
                type: number
                description: Unit cost of the item
          description: List of items received
        status:
          type: string
          enum: [pending, received, cancelled]
          description: Status of the receiving material
        notes:
          type: string
          description: Additional notes
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
    ReceivingMaterialUpdateResult:
      $ref: "#/components/schemas/ReceivingMaterialSchema"
      description: Result of updating a receiving material
