asyncapi: 3.0.0
id: 'https://ch.kochse/educ/plantit/greenhouse/api'
info:
  title: Plantit-Greenhouse
  version: '2.1.5'
  description: Manages Greenhouse spaces, reservations and 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:
  greenhouseInquiry:
    address:  'T.plantit.prod.greenhouse'
    messages:
      ReservationReq:
        defaultContentType: application/json
        $ref: '#/components/messages/PlantingReservationReqMsg'
        response:
          $ref: '#/components/messages/PlantingReservationRspMsg'
  greenhouseRequest:
    address: 'Q.plantit.prod.greenhouse.{greenhouseNo}'
    messages:
      OrderReq:
        $ref: '#/components/messages/PlantingOrderReqMsg'
        defaultContentType: application/json
        response:
          $ref: '#/components/messages/PlantingOrderRspMsg'
      CancellationReq:
        $ref: '#/components/messages/PlantingCancellationReqMsg'
    parameters:
      greenhouseNo:
        $ref: '#/components/parameters/greenhouse-no'
    bindings:
      amqp:
        queue:
          name: 'Q.plantit.prod.greenhouse.{greenhouseNo}'
          type: queue
          durable: false
          exclusive: true
          autoDelete: false
operations:
  reserve:
    action: receive
    channel:
      $ref: '#/channels/greenhouseInquiry'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/PlantingOrderRspMsg'
  order:
    action: receive
    channel:
      $ref: '#/channels/greenhouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/PlantingOrderRspMsg'
  cancel:
    action: receive
    channel:
      $ref: '#/channels/greenhouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
       - $ref: '#/components/messages/PlantingCancellationRspMsg'
  notify:
    action: receive
    channel:
      $ref: '#/channels/greenhouseRequest'
    reply: 
      address:
        location: '$message.header#/replyTo'
      messages:
        - $ref: '#/components/messages/PlantingGoodsReadyNotificationMsg'

components:
  messages:
    PlantingReservationReqMsg:
      name: Greenhouse Reservation Request
      title: Greenhouse Reservation Request
      summary: Inquiry of a reservation for growing some fruits or vegetables
      contentType: application/json
      payload:
        $ref: '#/components/schemas/PlantingReservationReqDTO'    

    PlantingReservationRspMsg:
      name: Reservation Response
      title: Greenhouse Reservation Response
      summary: Inquiry of a reservation for growing some fruits or vegetables
      contentType: application/json
      payload:
        $ref: '#/components/schemas/PlantingReservationRspDTO'    
        
    PlantingOrderReqMsg:
      name: Order Request
      title: Greenhouse Order Request
      summary: Definitive order or change of a reservation to an order
      payload:
        $ref: '#/components/schemas/PlantingOrderReqDTO'

    PlantingOrderRspMsg:
      name: Order Response
      title: Greenhouse Order Response
      summary: Definitive order or change of a reservation to an order 
      payload:
        $ref: '#/components/schemas/PlantingOrderRspDTO'      

    PlantingCancellationReqMsg: 
      name: Cancellation Request
      title: Greenhouse Order or Reservation Cancellation
      summary: Cancellation of a reservation or an order before the started state
      payload:
        $ref: '#/components/schemas/PlantingCancellationReqDTO'

    PlantingCancellationRspMsg: 
      name: Cancellation Response
      title: Greenhouse Order or Reservation Cancellation
      summary: Cancellation of a reservation or an order before the started state
      contentType: application/json
      payload:
        $ref: '#/components/schemas/PlantingCancellationRspDTO'
            
    PlantingGoodsReadyNotificationMsg: 
      name: Goods Ready Notification
      title: Greenhouse Goods Ready  Notification
      summary: Notification of the goods of an order ready to pickup
      contentType: application/json
      payload:
        $ref: '#/components/schemas/PlantingGoodsReadyRspDTO'

  schemas:
    PlantingReservationReqDTO:
      type: object
      properties:
        inquiryId: 
          type: string
          description: 'uuid to correlate the reservation to the corresponding order'
        productId:
          type: string
          description: 'product identifier'
        productname: 
          type: string
          description: 'short description such as name of the product'
        unit:
          $ref: '#/components/schemas/ProductUnit'
          description: 'quantity related unit of product'
        plannedDelivery:
          type: string
          format: date-time
          description: 'requested delivery date of the required or minimal quantity of the product'
        requiredQty: 
          type: number
          description: 'requested quantity of product to grow and deliver'
        minimalQty:
          type: number
          description: 'minimal quantity to reserve in case the complete quatity cannot be covered. Field only relevant in deliveryMode PARTIAL'
        deliveryMode:
          $ref: '#/components/schemas/DeliveryMode'
          description: 'defines if the delivery of an requested quantity has to be delivered in one or possibly parially'

    PlantingReservationRspDTO:
      type: object
      properties:
        reservationStatus:
          $ref: '#/components/schemas/DeliveryStatus'
        plantingId:
          type: string
          description: reservation id of the reservation
        name:
          type: string
          description: Name of the greenhouse location
        inquiryId:
          type: string
          description: uuid to correlate the reservation to corresponding order
        productId:
          type: string
          description: product identifier
        productname:
          type: string
          description: short description such as name of the product
        plannedDelivery:
          type: string
          format: date-time
          description: requested delivery date of the of the product of the inquirer
        expectedDelivery:
          type: string
          format: date-time
          description: expected delivery date of the reserved quantity of the product
        unit:
          $ref: '#/components/schemas/ProductUnit'
          description: quantity related unit of product
        requiredQty:
          type: number
          description: >-
            requested quantity of product to grow and deliver. This quantity
            must be the same or less than the 
        reservedQty:
          type: number
          description: effectively reserved quanity. 0 means minimalQty cannot be satisfied
        deliveryMode:
          $ref: '#/components/schemas/DeliveryMode'
          description: >-
            defines if the delivery of an requested quantity has to be delivered
            in one or possibly parially
        completion:
          $ref: '#/components/schemas/CompletionInfo'

    PlantingOrderReqDTO: 
      type: object
      properties:
        plantingId:
          type: string
          description: reservation id of the reservation of the supplier
        inquiryId:
          type: string
          description: >-
            uuid to correlate the reservation to corresponding order of the
            inquirer
        productId:
          type: string
          description: product identifier
        productname:
          type: string
          description: short description such as name of the product
        plannedDelivery:
          type: string
          format: date-time
          description: >-
            planned delivery date by the iquirer of the ordered quantity of the
            product
        orderedQty:
          type: number
          description: >-
            requested quantity of product to grow and deliver. This quantity has
            to be the same or less than the reserved quanity
        unit:
          $ref: '#/components/schemas/ProductUnit'
          description: quantity related unit of product
        deliveryMode:
          $ref: '#/components/schemas/DeliveryMode'
          description: >-
            defines if the delivery of an requested quantity has to be delivered
            in one or possibly parially

    PlantingOrderRspDTO: 
      type: object
      properties:
        plantingId:
          type: string
          description: id of the reservation or order
        name:
          type: string
          description: Name of the greenhouse location
        inquiryId:
          type: string
          description: uuid to correlate the reservation to corresponding order
        orderStatus:
          $ref: '#/components/schemas/DeliveryStatus'
          description: status of the order after last transaction
        productId:
          type: string
          description: product identifier
        productname:
          type: string
          description: short description such as name of the product
        expectedDelivery:
          type: string
          format: date-time
          description: expected delivery date of the amount of the product
        orderedQty:
          type: number
          description: requested quantity of product to grow and deliver
        unit:
          $ref: '#/components/schemas/ProductUnit'
          description: quantity related unit of product
        deliveryMode:
          $ref: '#/components/schemas/DeliveryMode'
          description: >-
            defines if the delivery of an requested quantity has to be delivered
            in one or possibly parially
        completion:
          $ref: '#/components/schemas/CompletionInfo'

    PlantingCancellationReqDTO:
      type: object
      properties:
        plantingId:
          type: string
          description: id of the reservation or order
        inquiryId:
          type: string
          description: uuid to correlate the reservation to corresponding order
        reason:
          type: string
          description: reason for the cancellation
          
    PlantingCancellationRspDTO:
      type: object
      properties:
        plantingId:
          type: string
          description: id of the reservation or order
        name:
          type: string
          description: Name of the greenhouse location
        inquiryId:
          type: string
          description: uuid to correlate the reservation to corresponding order
        cancellationStatus:
          $ref: '#/components/schemas/DeliveryStatus'
          description: >-
            new status after cancellation. cancelled = ok, denied = to late to
            cancel order, delivery will be executed
        completion:
          $ref: '#/components/schemas/CompletionInfo'
    
    PlantingGoodsReadyRspDTO:
      type: object
      properties:
        plantingId:
          type: string
          description: planting id of the reservation or order
        name:
          type: string
          description: Name of the greenhouse location
        inquiryId:
          type: string
          description: uuid to correlate to the to corresponding reservation or order
        deliveryStatus:
          $ref: '#/components/schemas/DeliveryStatus'
          description: defines the current state of the delivery
        pickupLocation:
          $ref: '#/components/schemas/PickupLocation'
          description: location id where goods can be picked up
        deliveryDate:
          type: string
          description: time when goods can be picked up
          format: date-time
        info:
          type: string
          description: additional information about the delivered goods
        completion:
          $ref: '#/components/schemas/CompletionInfo'
    PickupLocation:
      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
    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'

    ProductUnit:
      type: string
      enum:
        - kg
        - ton
        - liter
        - m3
        - pcs
      description: quantity related unit of product
    DeliveryMode:
      type: string
      enum:
        - complete
        - parital
      description: >-
        defines if the delivery of an requested quantity has to be delivered in
        one or possibly parially
    DeliveryStatus:
      type: string
      enum:
        - unavailable
        - reserved
        - ordered
        - cancelled
        - planted
        - growing
        - harvested
        - depraved
        - delivered
        - complete
        - undefined
  parameters:
    greenhouse-no:
      description: The greenhouse number
