openapi: 3.1.0
info:
  title: Business-Irdgco-Logistic
  description: Business-Irdgco-Logistic
  version: 1.1.0
servers:
  - url: 'https://qa.api.co.irdigital.pe'
    description: 'QA Environment'
security:
  - bearerAuth: []
  - basicAuth: []
tags:
  - name: Configuration
    description: Apis de configuracion
  - name: Capacity
    description: Apis de consulta de capacidades
paths:
  /api/business-irdgco-delivery/v1/configuration/load:
    post:
      summary: 'Load Configuration'
      description: 'Load Configuration'
      operationId: loadConfiguration
      tags:
        - Configuration
      responses:
        '200':
          description: 'Successful Response'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfigurationLoadResponse'
        '400':
          description: 'Bad Request'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/business-irdgco-delivery/v1/delivery/capacity:
    post:
      summary: 'Calculate Delivery Capacity'
      description: |
        Calcula la capacidad de entrega, soportando agrupación de ítems por origen y permitiendo diferentes tipos de despacho y destinos para los grupos de ítems.
      operationId: calculateDeliveryCapacity
      tags:
        - Capacity
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CalculateDeliveryCapacityRequest'
        required: true
      responses:
        '200':
          description: 'Successful Response'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CalculateDeliveryCapacityResponse'
        '400':
          description: 'Bad Request'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token enviado en el header Authorization usando el esquema Bearer.
    basicAuth:
      type: http
      scheme: basic
      description: Credenciales usuario/password enviadas en el header Authorization usando Basic Auth.
  schemas:
    ConfigurationLoadResponse:
      type: object
      properties:
        message:
          type: string
          description: 'Message indicating the status of the configuration load'
    CalculateDeliveryCapacityRequest:
      type: object
      properties:
        identifier:
          type: string
          description: 'Unique identifier for the delivery capacity calculation request'
        sellerId:
          type: string
          description: 'Seller ID for the delivery capacity calculation request'
        purchaseDate:
          type: string
          format: date
          description: 'Purchase date in ISO 8601 format'
        isLastRoute:
          type: boolean
          description: 'Indicates if this is the last route'
        dispatchType:
          type: string
          enum:
            - NORMAL
            - EXPRESS
          description: 'Type of dispatch: NORMAL, EXPRESS'
        dispatchMode:
          type: string
          enum:
            - HOME_DELIVERY
            - STORE_WITHDRAWAL
            - ALL_DISPATCH_MODES
          description: 'Type of dispatch: HOME_DELIVERY, STORE_WITHDRAWAL, ALL_DISPATCH_MODES'
        saleChannel:
          type: string
          description: 'Sale channel for the delivery'
        entitySale:
          type: string
          description: 'Entity code of the entity making the sale'
        hasFreightAttributeConfiguration:
          type: boolean
          description: 'Indicates if the delivery has freight attribute configuration'
          default: false
        calculationOptions:
          $ref: '#/components/schemas/CalculationOptionsRequest'
        deliveryData:
          $ref: '#/components/schemas/DeliveryDataRequest'
        items:
          type: array
          items:
            $ref: '#/components/schemas/ItemCapacityRequest'
      required:
        - purchaseDate
        - saleChannel
        - deliveryData
        - items
    CalculationOptionsRequest:
      type: object
      properties:
        calculate:
          type: string
          enum:
            - SEARCH_ORIGINS_BY_COORDINATES
            - SEARCH_ORIGINS_BY_ROUTE
        rangeStart:
          type: string
          format: date
        rangeEnd:
          type: string
          format: date
        optimization:
          type: string
          enum:
            - PROXIMITY_STORE
            - UBIGEO_NEAREST_STORE
            - COMPLETE_STOCK_MULTI_ORIGIN
            - ONLY_STOCK_SINGLE_ORIGIN
        maxOrigins:
          type: integer
        maxItemsPerOrigin:
          type: integer
        maxDistancePickingStore:
          type: integer
        maxPickupPoint:
          type: long
        validateStock:
          type: boolean
        dispatchCostEnabled:
          type: boolean
        pickupCompanyCode:
          type: string
        useExternalPickupCompanyCode:
          type: boolean
        useExternalDeliveryCompanyCode:
          type: boolean
    DeliveryDataRequest:
      type: object
      properties:
        latitude:
          type: number
          format: double
          description: 'Latitude of the delivery location'
        longitude:
          type: number
          format: double
          description: 'Longitude of the delivery location'
        zone:
          type: string
          description: 'Zone of the delivery'
        ubigeoCode:
          type: string
        destination:
          type: string
        originEntityCode:
          type: string
          description: 'Entity code of the origin of the delivery'
    ItemCapacityRequest:
      type: object
      properties:
        skuCode:
          type: string
          description: 'SKU code of the item'
        origin:
          type: string
          description: 'SKU code of the item'
        description:
          type: string
          description: 'Description of the item'
        routePriority:
          type: integer
          description: 'Priority of the route for the item'
        companyCode:
          type: string
          description: 'SKU code of the item'
        line:
          type: string
          description: 'Line number of the item'
        quantity:
          type: number
          format: double
          description: 'Quantity of the item'
        weight:
          type: number
          format: double
          description: 'Weight of the item in grams'
        height:
          type: number
          format: double
        width:
          type: number
          format: double
        length:
          type: number
          format: double
        volume:
          type: number
          format: double
        presentationCode:
          type: string
          description: 'Presentation code of the item'
        division:
          type: string
          description: 'Division of the item'
        units:
          type: integer
          description: 'Number of units of the item'
        measurable:
          type: string
          description: 'Indicates if the item is measurable'
        attributes:
          type: array
          items:
            $ref: '#/components/schemas/ItemAttributeCapacityRequest'
    ItemAttributeCapacityRequest:
      type: object
      properties:
        attribute:
          type: string
          description: 'Attribute of the item'
        attributeValue:
          type: string
          description: 'Value of the item attribute'
        attributeCode:
          type: string
          description: 'Code of the item attribute'
    CalculateDeliveryCapacityResponse:
      type: object
      properties:
        identifier:
          type: string
          description: 'Unique identifier for the delivery capacity calculation response, matching the request identifier'
        logisticsCapacity:
          type: array
          description: 'Lista de resultados de capacidad de entrega por grupo de origen'
          items:
            $ref: '#/components/schemas/DeliveryCapacityGroupResponse'
        prioritizationCriteria:
          type: string
          description: 'Criteria used for prioritizing the delivery capacity groups'
    DeliveryCapacityGroupResponse:
      type: object
      properties:
        origin:
          type: string
          description: 'Origen de este grupo'
        destination:
          type: string
          description: 'Destino de este grupo'
        dispatchType:
          type: string
          enum:
            - NORMAL
            - EXPRESS
          description: 'Type of dispatch: NORMAL, EXPRESS'
        dispatchMode:
          type: string
          enum:
            - HOME_DELIVERY
            - STORE_WITHDRAWAL
            - ALL_DISPATCH_MODES
          description: 'Type of dispatch: HOME_DELIVERY, STORE_WITHDRAWAL, ALL_DISPATCH_MODES'
        deliveryCost:
          type: number
          format: double
        zone:
          type: string
        pickingDays:
          type: array
          items:
            type: string
            enum:
              - LUN
              - MAR
              - MIE
              - JUE
              - VIE
              - SAB
              - DOM
        processingDays:
          type: integer
        leadTimes:
          type: array
          items:
            type: integer
        routeDaysOfWeek:
          type: array
          items:
            type: array
            items:
              type: string
        route:
          type: string
        routeDescription:
          type: string
        pickingDate:
          type: string
        deliveryDates:
          type: array
          items:
            type: string
            description: 'Fechas de entrega disponibles para este origen'
            examples: [ [ '2023-10-25' ] ]
        originEntityDetails:
          $ref: '#/components/schemas/EntityDetailResponse'
        pickupEntityDetails:
          $ref: '#/components/schemas/EntityDetailResponse'
        deliveryTrace:
          type: array
          items:
            $ref: '#/components/schemas/DeliveryTraceResponse'
        arriveDates:
          type: array
          items:
            $ref: '#/components/schemas/ArriveDateResponse'
        message:
          type: string
          description: 'Mensaje general sobre la operación'
        detailedCapacityError:
          type: array
          items:
            $ref: '#/components/schemas/DetailedCapacityErrorResponse'
        detailedCapacityWarning:
          type: array
          items:
            $ref: '#/components/schemas/DetailedCapacityWarningResponse'
        dispatchItems:
          type: array
          items:
            $ref: '#/components/schemas/ItemCapacityRequest'
        isWholesale:
          type: boolean
          description: 'Indicates if the delivery is wholesale'
        wholesaleAdditionalDays:
          type: integer
          description: 'Additional days for wholesale deliveries'
    EntityDetailResponse:
      type: object
      properties:
        entityType:
          type: string
        entityCode:
          type: string
        name:
          type: string
        shortName:
          type: string
        vtexWarehouseId:
          type: string
        vtexDockId:
          type: string
        contactNumber:
          type: string
        pickupPointId:
          type: string
        deliveryTime:
          type: string
        addressInfo:
          type: object
          properties:
            address:
              type: string
            district:
              type: string
            province:
              type: string
            ubigeoCode:
              type: string
            country:
              type: string
            latitude:
              type: number
              format: double
            longitude:
              type: number
              format: double
        distanceInfo:
          type: object
          properties:
            distance:
              type: number
              format: double
            unit:
              type: string
    DeliveryTraceResponse:
      type: object
      properties:
        deliveryDate:
          type: string
          description: 'Date of the delivery in ISO 8601 format'
        shippingEstimate:
          type: long
          description: 'Number of estimated shipping days'
        details:
          type: array
          items:
            $ref: '#/components/schemas/DeliveryTraceDetailResponse'
        deliveryWindows:
          type: array
          items:
            $ref: '#/components/schemas/DeliveryWindowResponse'
    DeliveryTraceDetailResponse:
      type: object
      properties:
        sourceNode:
          type: string
          description: 'Source node of the delivery trace'
        targetNode:
          type: string
          description: 'Target node of the delivery trace'
        route:
          type: string
          description: 'Route of the delivery trace'
        usedDispatchCapacity:
          type: integer
          description: 'Used dispatch capacity for the delivery trace'
        usedPickingCapacity:
          type: integer
          description: 'Used picking capacity for the delivery trace'
        dispatchDate:
          type: string
          description: 'Dispatch date in ISO 8601 format'
        dispatchUnits:
          type: integer
          description: 'Number of dispatch units'
        leadTime:
          type: integer
          description: 'Lead time for the delivery trace'
        daysOfWeek:
          type: string
          description: 'Days of the week for the delivery trace'
        departureDate:
          type: string
          description: 'Departure date in ISO 8601 format'
        receptionDate:
          type: string
          description: 'Reception date in ISO 8601 format'
    DeliveryWindowResponse:
      type: object
      properties:
        deliveryWindow:
          type: string
          description: 'Delivery window for the delivery trace'
        deliveryWindowStart:
          type: string
          description: 'Start time of the delivery window in ISO 8601 format'
        deliveryWindowEnd:
          type: string
          description: 'End time of the delivery window in ISO 8601 format'
        blocked:
          type: boolean
          description: 'Indicates if the delivery window is blocked'
    ArriveDateResponse:
      type: object
      properties:
        node:
          type: string
          description: 'Node for the arrive date'
        arriveDate:
          type: string
          description: 'Arrive date in ISO 8601 format'
    DetailedCapacityErrorResponse:
      type: object
      properties:
        code:
          type: string
          enum:
            - STOCK_ERROR
            - CAPACITY_ERROR
            - PROVIDER_ERROR
          description: 'Error code for the detailed capacity error'
        details:
          type: array
          items:
            $ref: '#/components/schemas/DetailedCapacityErrorDetailDTO'
        providerDetails:
          $ref: '#/components/schemas/ProviderErrorDetailDTO'
    DetailedCapacityWarningResponse:
      type: object
      properties:
        code:
          type: string
          enum:
            - CAPACITY_WARNING
          description: 'Warning detail or validation'
        details:
          type: array
          items:
            $ref: '#/components/schemas/DetailedCapacityWarningDetailDTO'
    ProviderErrorDetailDTO:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        detail:
          type: string
        detailCapacity:
          type: array
          items:
            $ref: '#/components/schemas/ProviderErrorDetailedCapacityErrorDetailDTO'
        detailStock:
          type: array
          items:
            $ref: '#/components/schemas/ProviderErrorDetailedStockErrorDetailDTO'
    ProviderErrorDetailedCapacityErrorDetailDTO:
      type: object
      properties:
        message:
          type: string
    ProviderErrorDetailedStockErrorDetailDTO:
      type: object
      properties:
        sku:
          type: string
        requestedQuantity:
          type: number
          format: double
        availableQuantity:
          type: number
          format: double
        warningMessage:
          type: string
    DetailedCapacityErrorDetailDTO:
      type: object
      properties:
        errorCode:
          type: string
          enum:
            - SOLD_OUT_QUANTITY
            - PRODUCT_NOT_AVAILABLE
            - PRODUCT_NOT_FOUND
            - PRODUCT_STOCK_NOT_FOUND
            - PRODUCT_STOCK_NOT_AVAILABLE
            - INSUFFICIENT_STOCK
            - PRODUCT_STOCK_NOT_VALUE_DEFINED
            - ROUTE_NOT_EXIST
            - ROUTE_CONFIGURATION_ERROR
            - DISPATCH_NOT_AVAILABLE
            - CALCULATION_CAPACITY_COST_ERROR
            - CAPACITY_CONFIGURATION_ERROR
            - CAPACITY_REQUEST_ERROR
            - SERVICE_ERROR
            - GENERIC_ERROR
        description:
          type: string
        sku:
          type: string
        requestedQuantity:
          type: number
          format: double
        availableQuantity:
          type: number
          format: double
    DetailedCapacityWarningDetailDTO:
      type: object
      properties:
        errorCode:
          type: string
          enum:
            - CAPACITY_CONFIGURATION_WARNING
            - DELIVERY_WINDOWS_WARNING
        description:
          type: string
        sku:
          type: string
    ErrorResponse:
      type: object
      properties:
        code:
          type: string
          description: 'Error code for the response'
        message:
          type: string
          description: 'Error message for the response'
        details:
          type: object
          additionalProperties: true
          description: 'Additional details about the error'