---
asyncapi: 3.0.0
info:
  title: Ordering Service API
  version: 1.0.0
  description: Orchestrates the entire order lifecycle, from creation to completion or cancellation, for the BookWorm platform
  contact:
    name: Nhan Nguyen
    url: "https://github.com/foxminchan"
  license:
    name: MIT
    url: "https://opensource.org/licenses/MIT"
defaultContentType: application/vnd.masstransit+json
servers:
  development:
    host: dev.eventbus:5672
    protocol: amqp
    protocolVersion: 0.9.1
    summary: RabbitMQ server for development environment
    description: RabbitMQ server for development environment
    security:
      - type: userPassword
        description: An authentication method for the server
    tags:
      - name: env:development
        description: >-
          Development environment configuration for local testing and debugging
  staging:
    host: stg.eventbus:5672
    protocol: amqp
    protocolVersion: 0.9.1
    summary: RabbitMQ server for staging environment
    description: RabbitMQ server for staging environment
    security:
      - type: userPassword
        description: An authentication method for the server
    tags:
      - name: env:staging
        description: >-
          Staging environment configuration for testing and debugging
  qa:
    host: qa.eventbus:5672
    protocol: amqp
    protocolVersion: 0.9.1
    summary: RabbitMQ server for QA environment
    description: RabbitMQ server for QA environment
    security:
      - type: userPassword
        description: An authentication method for the server
    tags:
      - name: env:qa
        description: >-
          QA environment configuration for testing and debugging
  production:
    host: prod.eventbus:5672
    protocol: amqp
    protocolVersion: 0.9.1
    summary: RabbitMQ server for production environment
    description: RabbitMQ server for production environment
    security:
      - type: userPassword
        description: An authentication method for the server
    tags:
      - name: env:production
        description: >-
          Production environment configuration for production
channels:
  basket-checkout-complete:
    address: basket-checkout-complete
    description: Event emitted when a user completes a basket checkout
    messages:
      DeleteBasketCompleteCommand.message:
        $ref: "#/components/messages/deleteBasketCompleteCommand"
  basket-checkout-failed:
    address: basket-checkout-failed
    description: Event emitted when a user fails to complete a basket checkout
    messages:
      DeleteBasketFailedCommand.message:
        $ref: "#/components/messages/deleteBasketFailedCommand"
  "BookWorm.Contracts:UserCheckedOutIntegrationEvent":
    address: "BookWorm.Contracts:UserCheckedOutIntegrationEvent"
    description: Event emitted when a user checks out
    messages:
      UserCheckedOutIntegrationEvent.message:
        $ref: "#/components/messages/userCheckedOutIntegrationEvent"
  "BookWorm.Contracts:OrderStatusChangedToCompleteIntegrationEvent":
    address: "BookWorm.Contracts:OrderStatusChangedToCompleteIntegrationEvent"
    description: Event emitted when an order is completed
    messages:
      OrderStatusChangedToCompleteIntegrationEvent.message:
        $ref: "#/components/messages/orderStatusChangedToCompleteIntegrationEvent"
  "BookWorm.Contracts:OrderStatusChangedToCancelIntegrationEvent":
    address: "BookWorm.Contracts:OrderStatusChangedToCancelIntegrationEvent"
    description: Event emitted when an order is cancelled
    messages:
      OrderStatusChangedToCancelIntegrationEvent.message:
        $ref: "#/components/messages/orderStatusChangedToCancelIntegrationEvent"
operations:
  DeleteBasketCompleteCommand:
    title: Delete basket complete
    summary: Delete basket complete
    description: Represents a successful integration event when deleting a basket in the system
    action: receive
    channel:
      $ref: "#/channels/basket-checkout-complete"
    messages:
      - $ref: >-
          #/channels/basket-checkout-complete/messages/DeleteBasketCompleteCommand.message
  DeleteBasketFailedCommand:
    title: Delete basket failed
    summary: Delete basket failed
    description: Represents a failed integration event when deleting a basket in the system
    action: receive
    channel:
      $ref: "#/channels/basket-checkout-failed"
    messages:
      - $ref: >-
          #/channels/basket-checkout-failed/messages/DeleteBasketFailedCommand.message
  UserCheckedOutIntegrationEvent:
    title: User checked out
    summary: User checked out
    description: Represents a successful integration event when a user checks out
    action: send
    channel:
      $ref: "#/channels/BookWorm.Contracts:UserCheckedOutIntegrationEvent"
    messages:
      - $ref: >-
          #/channels/BookWorm.Contracts:UserCheckedOutIntegrationEvent/messages/UserCheckedOutIntegrationEvent.message
  OrderStatusChangedToCompleteIntegrationEvent:
    title: Order status changed to complete
    summary: Order status changed to complete
    description: Represents a successful integration event when an order is completed
    action: send
    channel:
      $ref: >-
        #/channels/BookWorm.Contracts:OrderStatusChangedToCompleteIntegrationEvent
    messages:
      - $ref: >-
          #/channels/BookWorm.Contracts:OrderStatusChangedToCompleteIntegrationEvent/messages/OrderStatusChangedToCompleteIntegrationEvent.message
  OrderStatusChangedToCancelIntegrationEvent:
    title: Order status changed to cancel
    summary: Order status changed to cancel
    description: Represents a successful integration event when an order is cancelled
    action: send
    channel:
      $ref: "#/channels/BookWorm.Contracts:OrderStatusChangedToCancelIntegrationEvent"
    messages:
      - $ref: >-
          #/channels/BookWorm.Contracts:OrderStatusChangedToCancelIntegrationEvent/messages/OrderStatusChangedToCancelIntegrationEvent.message
components:
  schemas:
    deleteBasketCompleteCommand:
      id: deleteBasketCompleteCommand
      description: Represents a successful integration event when deleting a basket in the system
      allOf:
        - $ref: "#/components/schemas/integrationEvent"
        - type: object
          additionalProperties: false
          properties:
            orderId:
              type: string
              format: guid
              description: The unique identifier of the order
              example: "019622e7-87ac-7bd1-aa9c-35803d8a1e50"
            totalMoney:
              type: number
              format: decimal
              description: The total amount of money in the basket
              minimum: 0
              example: 100.00
    integrationEvent:
      id: integrationEvent
      type: object
      description: Base event structure containing common metadata for all integration events in the system
      additionalProperties: false
      properties:
        id:
          type: string
          format: guid
          description: The unique identifier of the integration event
          example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
        creationDate:
          type: string
          format: date-time
          description: The creation date of the integration event
          example: "2021-01-01T00:00:00Z"
    deleteBasketFailedCommand:
      id: deleteBasketFailedCommand
      description: Represents a failed integration event when deleting a basket in the system
      allOf:
        - $ref: "#/components/schemas/integrationEvent"
        - type: object
          additionalProperties: false
          properties:
            basketId:
              type: string
              format: guid
              description: The unique identifier of the basket
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            email:
              type:
                - "null"
                - string
              description: The email of the user
              pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
              example: "test@test.com"
            orderId:
              type: string
              format: guid
              description: The unique identifier of the order
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
    userCheckedOutIntegrationEvent:
      id: userCheckedOutIntegrationEvent
      description: Represents a successful integration event when a user checks out
      allOf:
        - $ref: "#/components/schemas/integrationEvent"
        - type: object
          additionalProperties: false
          properties:
            orderId:
              type: string
              format: guid
              description: The unique identifier of the order
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            basketId:
              type: string
              format: guid
              description: The unique identifier of the basket
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            email:
              type:
                - "null"
                - string
              description: The email of the user
              pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
              example: "test@test.com"
            totalMoney:
              type: number
              format: decimal
              description: The total amount of money in the basket
              minimum: 0
              example: 100.00
    orderStatusChangedToCompleteIntegrationEvent:
      id: orderStatusChangedToCompleteIntegrationEvent
      description: Represents a successful integration event when an order is completed
      allOf:
        - $ref: "#/components/schemas/integrationEvent"
        - type: object
          additionalProperties: false
          properties:
            orderId:
              type: string
              format: guid
              description: The unique identifier of the order
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            basketId:
              type: string
              format: guid
              description: The unique identifier of the basket
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            email:
              type:
                - "null"
                - string
              description: The email of the user
              pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
              example: "test@test.com"
            totalMoney:
              type: number
              format: decimal
              description: The total amount of money in the basket
              minimum: 0
              example: 100.00
    orderStatusChangedToCancelIntegrationEvent:
      id: orderStatusChangedToCancelIntegrationEvent
      description: Represents a successful integration event when an order is cancelled
      allOf:
        - $ref: "#/components/schemas/integrationEvent"
        - type: object
          additionalProperties: false
          properties:
            orderId:
              type: string
              format: guid
              description: The unique identifier of the order
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            basketId:
              type: string
              format: guid
              description: The unique identifier of the basket
              example: "01961eb4-668d-7e7e-ae25-0fab379614f7"
            email:
              type:
                - "null"
                - string
              description: The email of the user
              pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
              example: "test@test.com"
            totalMoney:
              type: number
              format: decimal
              description: The total amount of money in the basket
              minimum: 0
              example: 100.00
  messages:
    deleteBasketCompleteCommand:
      payload:
        $ref: "#/components/schemas/deleteBasketCompleteCommand"
      name: deleteBasketCompleteCommand
    deleteBasketFailedCommand:
      payload:
        $ref: "#/components/schemas/deleteBasketFailedCommand"
      name: deleteBasketFailedCommand
    userCheckedOutIntegrationEvent:
      payload:
        $ref: "#/components/schemas/userCheckedOutIntegrationEvent"
      name: userCheckedOutIntegrationEvent
    orderStatusChangedToCompleteIntegrationEvent:
      payload:
        $ref: "#/components/schemas/orderStatusChangedToCompleteIntegrationEvent"
      name: orderStatusChangedToCompleteIntegrationEvent
    orderStatusChangedToCancelIntegrationEvent:
      payload:
        $ref: "#/components/schemas/orderStatusChangedToCancelIntegrationEvent"
      name: orderStatusChangedToCancelIntegrationEvent
