asyncapi: 3.0.0
id: 'https://ch.kochse/educ/plantit/warehouse/api'
info:
  title: Plantit-Warehouse
  version: '2.1.3'
  description:  Manages warehouse spaces, reservations and checkin, checkout
  contact:
    email: plantit@kochse.ch
    name: Andres Koch
    url: 'https://www.kochse.ch'
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'
defaultContentType: application/json
servers: 
  production:
    protocol: amqp
    description: message broker for MAS/SE ADS exercise 
    host: 'tcp://masse-mq.dynu.net:62616'

channels:
  warehouseRequest:
    address: 'Q.plantit.prod.warehouse'
    messages:    
      Reservation:
        $ref: '#/components/messages/WarehouseReservationReqMsg'
      Cancellation: 
        $ref: '#/components/messages/WarehouseCancellationReqMsg'
      Checkin:
        $ref: '#/components/messages/WarehouseCheckinRspMsg'
      Checkout:
        $ref: '#/components/messages/WarehouseCheckinRspMsg'
operations:
  reserve:
    action: receive
    channel:
      $ref: '#/channels/warehouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/WarehouseReservationRspMsg' 
  cancel:
    action: receive
    channel:
      $ref: '#/channels/warehouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
      - $ref: '#/components/messages/WarehouseCancellationReqMsg'
  checkin:
    action: receive
    channel:
      $ref: '#/channels/warehouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/WarehouseCheckinRspMsg'
  checkout:
    action: receive
    channel:
      $ref: '#/channels/warehouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/WarehouseCheckoutRspMsg'
    
components:
  messages:
    WarehouseReservationReqMsg:
      name: WarehouseReservationRequest
      title: Warehouse Reservation 
      summary: Reservation of a stock place for a specific weight and volume
      contentType: application/json
      payload:
        $ref: '#/components/schemas/WarehouseReservationReqDTO'    

    WarehouseReservationRspMsg:
      name: WarehouseReservationResponse
      title: Warehouse Reservation Response
      summary: Warehouse reservation response with details of location
      contentType: application/json
      payload:
        $ref: '#/components/schemas/WarehouseReservationRspDTO'    
        
    WarehouseCancellationReqMsg:
        name: WarehouseCancellationResponse
        title: Cancellation a Warehouse Reservation Request
        summary: Canellation of an earlier stock reservation
        contentType: application/json
        payload:
          $ref: '#/components/schemas/WarehouseCancellationReqDTO'
 
    WarehouseCancellationRspMsg:
        name: WarehouseCancellationResponse
        title: Warehouse Cancellation Response
        summary: Acknowledge of the cancelled reservation
        contentType: application/json
        payload:
          $ref: '#/components/schemas/WarehouseCancellationRspDTO'   
        
    WarehouseCheckinReqMsg:
        name: WarehouseCheckinRequest
        title: Warehouse Checkin Request
        summary: Checkin request to a reserved place
        contentType: application/json
        payload:
          $ref: '#/components/schemas/WarehouseCheckinReqDTO'
 
    WarehouseCheckinRspMsg:
        name: WarehouseCheckinResponse
        title: Warehouse CheckIn Response
        summary: Acknowledge of the checkin of goods for a reservated place
        contentType: application/json
        payload:
          $ref: '#/components/schemas/WarehouseCheckinRspDTO'   
  
    WarehouseCheckoutReqMsg:
        name: WarehouseCheckOutRequest
        title: Warehouse CheckOut Request
        summary: Checkout request from a reserved place
        contentType: application/json
        payload:
          $ref: '#/components/schemas/WarehouseCheckoutReqDTO'
 
    WarehouseCheckoutRspMsg:
        name: WarehouseCheckoutResponse
        title: Warehouse Checkout  Response
        summary: Acknowledge of the checkout of goods from a reservated place. The place becomes avaiable after.
        contentType: application/json
        payload:
          $ref: '#/components/schemas/WarehouseCheckoutRspDTO'   
  schemas:
    WarehouseReservationReqDTO:
      type: object
      properties:
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to the corresponding order'
        productname: 
          type: string
          description: 'short description such as name of the product'
        plannedCheckin:
          type: string
          format: date-time
          description: 'Date and time when the checkin should occur'
        plannedCheckout:
          type: string
          format: date-time
          description: 'Date and time when the checkout should occur'        
        requiredWeight: 
          type: number
          description: 'The required weight in kg for the stock place'
        requiredVolume:
          type: number
          description: 'The required volume in m3 for the stock place'

    WarehouseReservationRspDTO:
      type: object
      properties:
        reservationStatus:
          $ref: '#/components/schemas/WarehouseStatus'
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'
        productname: 
          type: string
          description: 'short description such as name of the product'
        plannedCheckin:
          type: string
          format: date-time
          description: 'Date and time when the checkin should occur'
        plannedCheckout:
          type: string
          format: date-time
          description: 'Date and time when the checkout should occur'        
        requiredWeight: 
          type: number
          description: 'The required weight in kg for the stock place'
        requiredVolume:
          type: number
          description: 'The required volume in m3 for the stock place'
        stockLocation:
          $ref: '#/components/schemas/WarehouseLocation'
          description: 'Reserved stock place for the later checkin'
        completion:
          $ref: '#/components/schemas/CompletionInfo'
          description: Error Code according documentation

    WarehouseCancellationReqDTO:
      type: object
      properties:
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'

    WarehouseCancellationRspDTO:
      type: object
      properties:
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'
        reservationStatus:
          $ref: '#/components/schemas/WarehouseStatus'
        completion:
          $ref: '#/components/schemas/CompletionInfo'
          description: Error Code according documentation

    WarehouseCheckinReqDTO:
      type: object
      properties:
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'

    WarehouseCheckinRspDTO:
      type: object
      properties:
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'
        reservationStatus:
          $ref: '#/components/schemas/WarehouseStatus'
          description: 'status after checkin operation'
        completion:
          $ref: '#/components/schemas/CompletionInfo'
          description: Error Code according documentation


    WarehouseCheckoutReqDTO:
      type: object
      properties:
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'

    WarehouseCheckoutRspDTO:
      type: object
      properties:
        stockId:
          type: string
          description: 'reservation id of the stock place'
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to corresponding order'
        reservationStatus:
          $ref: '#/components/schemas/WarehouseStatus'
          description: 'status after checkout operation'
        completion:
          $ref: '#/components/schemas/CompletionInfo'
          description: Error Code according documentation

    WarehouseLocation:
      type: object
      properties:
        longitude:
          type: number
          description: 'longitude of location'
        latitude:
          type: number
          description: 'latitude of location'
        siteSpecifics:
          type: string
          description:  'specific instruction at site'
        
    WarehouseStatus:
      type: string
      enum:
        - 'unavailable'
        - 'reserved' 
        - 'cancelled' 
        - 'occupied' 
        - 'complete' 
        - 'undefined'
      default: 'undefined'        

    CompletionInfo:
      type: object
      properties:
        responseCode:
          type: integer
          description: 'Error code 0 = success <0 error codes >0 completion: code'
        responseMessage:
          type: string
          description: 'individual human readable completion: message'