asyncapi: 3.0.0
id: 'https://ch.kochse/educ/plantit/transport/api'
info:
  title: Plantit-Transport
  version: '2.1.3'
  description: Manages and executes transport orders
  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:
  TransportRequest:
    address: 'Q.plantit.prod.transport'
    messages:    
      Order:
        $ref: '#/components/messages/TransportOrderReqMsg'
      Cancellation: 
        $ref: '#/components/messages/TransportCancelReqMsg'
operations:
  order:
    action: receive
    channel:
      $ref: '#/channels/TransportRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/TransportOrderReqMsg'
  cancel:
    action: receive
    channel:
      $ref: '#/channels/TransportRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/TransportCancelReqMsg'
  notify:
    action: receive
    channel:
      $ref: '#/channels/TransportRequest'
    reply: 
      address:
        location: $message.header#/replyTo
      messages:
        - $ref: '#/components/messages/TransportCompletionNotification'

components:
  messages:
    TransportOrderReqMsg:
      name: TransportOrderReq
      title: Transport Order Request
      summary: Ordering of a transport
      contentType: application/json
      payload:
        $ref: '#/components/schemas/TransportOrderReqDTO'    

    TransportOrderRspMsg:
      name: TransportOrderRsp
      title: Transport Order Response
      summary: Response of an requested transport order
      contentType: application/json
      payload:  
        $ref: '#/components/schemas/TransportOrderRspDTO'    
        
    TransportCancelReqMsg:
        name: TransportCancelReq
        title: Transport Cancellation Request
        summary: Cancels a previous transport order
        contentType: application/json
        payload:
          $ref: '#/components/schemas/TransportCancelReqDTO'
 
    TransportCancelRspMsg:
        name: TransportCancelRsp
        title: Transport Cancellation Response
        summary: reply to a cancellation request
        contentType: application/json
        payload:
          $ref: '#/components/schemas/TransportCancelRspDTO'   
    
    TransportCompletionNotification:
        name: TransportCompletion
        title: Transport Completion Notification
        summary: notifies that an transport is completed
        contentType: application/json
        payload:
          payload:          
            $ref: '#/components/schemas/TransportCompletionDTO'   
  
  schemas:
    TransportOrderReqDTO:
      type: object
      properties:
        inquiryId: 
          type: string
          description: 'uuid to correlate the to the corresponding order'
        goodsName: 
          type: string
          description: 'short description of the goods'
        freightWeight:
          type: number
          description: 'weight of the freight in freightUnit' 
        freightUnit:
          $ref: '#/components/schemas/TransportUnit' 
          description: 'unit of the weight'
        freightVolume:
          type: number
          description: 'volume in m3 needed for the freight' 
        plannedLoading:
          type: string
          format: date-time
          description: 'planned loading time of the transport'
        loadingPoint:   
          $ref: '#/components/schemas/Terminal'
          description: 'Location where the freight has to be loaded'
        plannedUnloading:
          type: string
          format: date-time
          description: 'planned unloading time of the transport'
        unloadingPoint:   
          $ref: '#/components/schemas/Terminal'
          description: 'Location where the freight has to be unloaded'

    TransportOrderRspDTO:
      type: object
      properties:
        transportId:
          type: string
          description: 'transpor id of the order'
        transportStatus:
          $ref: '#/components/schemas/Status'
        inquiryId: 
          type: string
          description: 'uuid to correlate the to the corresponding order'
        goodsName: 
          type: string
          description: 'short description of the goods'
        freightWeight:
          type: number
          description: 'weight of the freight in freightUnit' 
        freightUnit:
          $ref: '#/components/schemas/TransportUnit' 
          description: 'unit of the weight'
        freightVolume:
          type: number
          description: 'volume in m3 needed for the freight' 
        plannedLoading:
          type: string
          format: date-time
          description: 'planned loading time of the transport'
        loadingPoint:   
          $ref: '#/components/schemas/Terminal'
          description: 'Location where the freight has to be loaded'
        plannedUnloading:
          type: string
          format: date-time
          description: 'planned unloading time of the transport'
        unloadingPoint:   
          $ref: '#/components/schemas/Terminal'
          description: 'Location where the freight has to be unloaded'
        completion:
          $ref: '#/components/schemas/CompletionInfo'        

    TransportCancelReqDTO:
      type: object
      properties:
        transportId:
          type: string
          description: 'transport id of the order'
        transportStatus:
          $ref: '#/components/schemas/Status'
        inquiryId: 
          type: string
          description: 'uuid to correlate to corresponding order'
        reason:
          type: string
          description: 'reason the transport order was cancelled'

    TransportCancelRspDTO:
      type: object
      properties:
        transportId:
          type: string
          description: 'transport id of the order'
        transportStatus:
          $ref: '#/components/schemas/Status'
        inquiryId: 
          type: string
          description: 'uuid to correlate to corresponding order'
        completion:
          $ref: '#/components/schemas/CompletionInfo'        

    TransportCompletionDTO: 
      type: object
      tag: CompletionInfo
      properties:
        transportId:
          type: string
          description: 'transpor id of the order'
        transportStatus:
          $ref: '#/components/schemas/Status'
          description: 'transport status'
        inquiryId: 
          type: string
          description: 'uuid to correlate to corresponding order'
        effectiveDelivery:
          type: string
          format: date-time
          description: 'planned delivery date by the iquirer of the ordered quantity of the product'
        deliveryLocation:
          $ref: '#/components/schemas/Location'
          description: 'Location where the freight has been unloaded'
        completion:
          $ref: '#/components/schemas/CompletionInfo'        

    TransportUnit:
      type: string
      enum: 
        - 'kg'
        - 'ton'
        - 'liter'
        - 'm3'
        - 'pcs'
      description: 'quantity related unit of goods'
   
    Location:
      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'

    Terminal: 
      type: object
      properties: 
        terminalType: 
          $ref: '#/components/schemas/TerminalType'
          description: 'type of terminal'
        location:
          $ref: '#/components/schemas/Location'
          description: 'location at terminal'
        reference:
          type: string
          description: 'reference for checking in/out at the terminal. can be empty'          
        
    TerminalType:    
      type: string
      enum: 
        - 'warehouse'
        - 'terminal'
        - 'gate'
        - 'openfield'

    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'

    Status:
      type: string
      enum:
        - 'unavailable'
        - 'ordered' 
        - 'cancelled' 
        - 'loaded' 
        - 'driving'
        - 'holding'
        - 'unloaded' 
        - 'complete' 
        - 'undefined'
      default: 'undefined'