openapi: 3.0.3

info:
  title: Products Upload API
  description: API para carga masiva de productos (JSON y CSV)
  version: 1.0.0

servers:
  - url: /api/business-irdgco-products-upload/v1

tags:
  - name: Products Upload
    description: Endpoints de carga de productos

components:

  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:

    ErrorMessage:
      type: object
      properties:
        message:
          type: string
          example: Error interno del servidor

    ProductLoadSuccess:
      type: object
      properties:
        message:
          type: string
          example: "Se estan procesando 5 productos. Codigo de proceso: 123e4567-e89b-12d3-a456-426614174000"

    ProductLoadErrorDTO:
      type: object
      properties:
        sku:
          type: string
          example: "20054992"
        error:
          type: string
          example: "hierarchies no puede estar vacío"

    ProductLoadResponseDTO:
      type: object
      properties:
        total:
          type: integer
          example: 10
        processing:
          type: integer
          example: 7
        failed:
          type: integer
          example: 3
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ProductLoadErrorDTO'

    ProductsList:
      type: object
      required:
        - products
      properties:
        products:
          type: array
          maxItems: 3000
          items:
            $ref: '#/components/schemas/DADProductDTO'

    DADProductDTO:
      type: object
      required:
        - productCode
        - skuCode
        - eanCode
        - description
        - price
        - length
        - width
        - height
        - weight
        - productType
        - unitedNationsCode
        - unitMeasurement
        - hierarchyCode
        - taxSale
        - productPmmStatus
        - dateUpdate
        - isEcommerce
        - measurable
        - conversionFactor
        - barcodes
        - hierarchies
        - lstAttributes
      properties:
        productCode:
          type: string
          example: SPSA-100001
        skuCode:
          type: string
          example: "20054992"
        eanCode:
          type: string
          example: "7750045225533"
        description:
          type: string
          example: TUINIES BIBERON RANA 8ONZ 22553
        price:
          type: number
          format: double
        length:
          type: number
          format: double
        width:
          type: number
          format: double
        height:
          type: number
          format: double
        weight:
          type: number
          format: double
        productType:
          type: string
          example: ST
        dispatchType:
          type: string
          nullable: true
        unitMeasurement:
          type: string
          example: UN
        unitedNationsCode:
          type: string
          example: "00601059"
        hierarchyCode:
          type: string
          example: SPSA-F0425
        companyCode:
          type: string
          nullable: true
        taxSale:
          type: string
          example: T
        taxSelective:
          type: number
          format: double
          nullable: true
        salesTax:
          type: number
          format: double
          nullable: true
        productPmmStatus:
          type: string
          example: "5"
        dateUpdate:
          type: string
          example: "2021-03-01 09:00:00"
        isEcommerce:
          type: string
          example: F
        measurable:
          type: string
          example: F
        skuCodeVtex:
          type: string
          nullable: true
        conversionFactor:
          type: integer
          format: int64
        barcodes:
          type: array
          items:
            $ref: '#/components/schemas/ProductBarcodeDTO'
        hierarchies:
          type: array
          items:
            $ref: '#/components/schemas/ProductHierarchyDTO'
        lstAttributes:
          type: array
          items:
            $ref: '#/components/schemas/ProductAttributeDTO'

    ProductBarcodeDTO:
      type: object
      required:
        - productCode
        - eanCode
        - indicator
      properties:
        productCode:
          type: string
        eanCode:
          type: string
        indicator:
          type: string

    ProductHierarchyDTO:
      type: object
      required:
        - hierarchyCode
        - hierarchyLevel
      properties:
        hierarchyCode:
          type: string
        hierarchyParent:
          type: string
        hierarchyName:
          type: string
        hierarchyLevel:
          type: integer
        hierarchyDescription:
          type: string
        hierarchyBreadcrumb:
          type: string
          nullable: true

    ProductAttributeDTO:
      type: object
      required:
        - attributeType
        - parentAttributeCode
        - attributeCode
        - attributeDescription
        - productCode
      properties:
        attributeType:
          type: string
        parentAttributeCode:
          type: string
        attributeCode:
          type: string
        attributeDescription:
          type: string
        attributeDescriptionDetail:
          type: string
        productCode:
          type: string

paths:

  /handle-json:
    post:
      tags:
        - Products Upload
      summary: Carga productos desde archivo JSON (multipart)
      security:
        - bearerAuth: []
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - productsJson
              properties:
                productsJson:
                  type: string
                  format: binary
      responses:
        '200':
          description: Archivo procesado correctamente

  /handle-json-int:
    post:
      tags:
        - Products Upload
      summary: Carga productos JSON indicando empresa
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - company
                - productsJson
              properties:
                company:
                  type: string
                  example: SPSA
                productsJson:
                  type: string
                  format: binary
      responses:
        '200':
          description: Archivo procesado correctamente

  /handle-csv:
    post:
      tags:
        - Products Upload
      summary: Carga productos desde archivos CSV
      security:
        - bearerAuth: []
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - productsCsv
                - hierarchiesCsv
                - barcodesCsv
                - attributesCsv
              properties:
                productsCsv:
                  type: string
                  format: binary
                hierarchiesCsv:
                  type: string
                  format: binary
                barcodesCsv:
                  type: string
                  format: binary
                attributesCsv:
                  type: string
                  format: binary
      responses:
        '200':
          description: Archivos procesados correctamente

  /load-products:
    post:
      tags:
        - Products Upload
      summary: Carga masiva de productos (JSON Body)
      description: Permite enviar hasta 3000 productos en formato JSON para su procesamiento.
      operationId: loadProducts
      security:
        - bearerAuth: []
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProductsList'

      responses:

        '200':
          description: Procesamiento correcto
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ProductLoadSuccess'
                  - $ref: '#/components/schemas/ProductLoadResponseDTO'

        '400':
          description: Número máximo de productos excedido
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
              example:
                message: "El número máximo de productos por carga es 3000"

        '500':
          description: Error enviando mensaje a PubSub
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
              example:
                message: "No se pudo enviar el mensaje a PubSub"

        '401':
          description: No autorizado

        '403':
          description: Prohibido