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
        - hierarchyParent
        - hierarchyName
        - hierarchyLevel
        - hierarchyDescription
      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
        - attributeDescriptionDetail
        - keySubAttribute
      properties:
        attributeType:
          type: string
        productCode:
          type: string  
        parentAttributeCode:
          type: string
        attributeCode:
          type: string
        attributeDescription:
          type: string
        attributeDescriptionDetail:
          type: string
        keySubAttribute:
          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'
            example:
              products:
                - productCode: "OE-2796064"
                  skuCode: "2833000"
                  eanCode: "2800028330008"
                  description: "TT POD PMC RYANN VTT COL NEGRO XL"
                  price: 39.95
                  length: 1
                  width: 1
                  height: 1
                  weight: 1
                  productType: "ST"
                  dispatchType: "BTA"
                  unitMeasurement: "UN"
                  unitedNationsCode: "53102902"
                  hierarchyCode: "OE-L0817"
                  taxSale: "F"
                  productPmmStatus: "5"
                  dateUpdate: "2020-01-01 00:00:01"
                  isEcommerce: "F"
                  measurable: "F"
                  conversionFactor: 1
                  barcodes:
                    - productCode: "OE-2796064"
                      eanCode: "2800028330008"
                      indicator: "T"
                  hierarchies:
                    - hierarchyDescription: "POLOS"
                      hierarchyCode: "OE-L0817"
                      hierarchyParent: "OE-D096"
                      hierarchyName: "LINEA"
                      hierarchyLevel: 4
                    - hierarchyDescription: "DEPORTE HOMBRE O"
                      hierarchyCode: "OE-D096"
                      hierarchyParent: "OE-A11"
                      hierarchyName: "DEPARTAMENTO"
                      hierarchyLevel: 3
                    - hierarchyDescription: "TEXTIL DEPORTE"
                      hierarchyCode: "OE-A11"
                      hierarchyParent: "OE-T03"
                      hierarchyName: "AREA"
                      hierarchyLevel: 2
                    - hierarchyDescription: "DEPORTES"
                      hierarchyCode: "OE-T03"
                      hierarchyParent: ""
                      hierarchyName: "DIVISION"
                      hierarchyLevel: 1
                  lstAttributes:
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST182"
                      attributeCode: "OE-ATTR606467"
                      attributeDescription: "2025"
                      productCode: "OE-2796064"
                      keySubAttribute: "ANO"
                      attributeDescriptionDetail: "2025"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST202"
                      attributeCode: "OE-ATTR590891"
                      attributeDescription: "VTT"
                      productCode: "OE-2796064"
                      keySubAttribute: "VENTANA"
                      attributeDescriptionDetail: "SI"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST203"
                      attributeCode: "OE-ATTR591063"
                      attributeDescription: "SI"
                      productCode: "OE-2796064"
                      keySubAttribute: "WEB"
                      attributeDescriptionDetail: "WWW"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST207"
                      attributeCode: "OE-ATTR593844"
                      attributeDescription: "LONG TERM"
                      productCode: "OE-2796064"
                      keySubAttribute: "CICLO DE VIDA"
                      attributeDescriptionDetail: "LONG TERM"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST208"
                      attributeCode: "OE-ATTR593848"
                      attributeDescription: "BEST SELLER"
                      productCode: "OE-2796064"
                      keySubAttribute: "TIPO DE ROTACION"
                      attributeDescriptionDetail: "BEST SELLER"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST215"
                      attributeCode: "OE-ATTR597127"
                      attributeDescription: "XXS"
                      productCode: "OE-2796064"
                      keySubAttribute: "TAMANO"
                      attributeDescriptionDetail: "XXS"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST45"
                      attributeCode: "OE-ATTR231"
                      attributeDescription: "TODA TEMPORADA"
                      productCode: "OE-2796064"
                      keySubAttribute: "TEMPORADA"
                      attributeDescriptionDetail: "TODA TEMPORADA"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST46"
                      attributeCode: "OE-ATTR233"
                      attributeDescription: "IMPORTADO"
                      productCode: "OE-2796064"
                      keySubAttribute: "PROCEDENCIA"
                      attributeDescriptionDetail: "IMPORTADO"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST50"
                      attributeCode: "OE-ATTR246"
                      attributeDescription: "BASICO"
                      productCode: "OE-2796064"
                      keySubAttribute: "PIRAMIDE MIX"
                      attributeDescriptionDetail: "BASICO"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST51"
                      attributeCode: "OE-ATTR249"
                      attributeDescription: "PROPIA"
                      productCode: "OE-2796064"
                      keySubAttribute: "TIPO DE NEGOCIACION"
                      attributeDescriptionDetail: "PROPIA"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST52"
                      attributeCode: "OE-ATTR252"
                      attributeDescription: "PROPIA"
                      productCode: "OE-2796064"
                      keySubAttribute: "PROPIA O DE PROV"
                      attributeDescriptionDetail: "PROPIA"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST53"
                      attributeCode: "OE-ATTR3779"
                      attributeDescription: "PODIUM"
                      productCode: "OE-2796064"
                      keySubAttribute: "NOMBRE DE MARCA"
                      attributeDescriptionDetail: "PODIUM"
                    - attributeType: "ATRIBUTO"
                      parentAttributeCode: "OE-AST83"
                      attributeCode: "OE-ATTR533"
                      attributeDescription: "S-M-L-XL"
                      productCode: "OE-2796064"
                      keySubAttribute: "TIPO DE CURVA TALLA"
                      attributeDescriptionDetail: "S-M-L-XL"
                  salesTax: 15.0

      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
