openapi: 3.0.1
info:
  title: Notification module
  description: |
    Hand-made OpenAPI document for Notification module.
  version: 1.0.0
servers:
  - url: "http://localhost:8083"
tags:
  - name: NotificationService
components:
  schemas:
    NotificationDto:
      type: object
      title: Notification
      description: Notification to be send to receivers
      required:
        - message
        - receivers
        - subject
      properties:
        message:
          type: string
          description: Content of the email
        receivers:
          type: array
          items:
            type: string
          description: Email addresses the notification is sent to
        subject:
          type: string
          description: Subject of the email
    CarComponentNotificationDto:
      type: object
      title: CarComponentNotification
      description: Notification about new component
      required:
        - carComponent
        - receivers
      properties:
        carComponent:
          $ref: "#/components/schemas/CarComponentDto"
        receivers:
          type: array
          items:
            type: string
          description: Email addresses the notification is sent to
    ApplicationNotificationDto:
      type: object
      title: ApplicationNotification
      description: Application notification
      required:
        - application
        - receivers
      properties:
        application:
          $ref: "#/components/schemas/ApplicationDto"
        receivers:
          type: array
          items:
            type: string
          description: Email addresses the notification is sent to
    ConfirmationDto:
      type: object
      title: Confirmation
      properties:
        message:
          type: string
        subject:
          type: string
          description: Subject of the email
        receivers:
          type: array
          items:
            type: string
          description: Email addresses the notification was sent to
        sender:
          type: string
          description: Email address from which the notification was sent

    CarComponentType:
      type: string
      description: Type of a component
      enum:
        - CHASSIS
        - ENGINE
        - FRONTWING
        - SUSPENSION
    CarComponentDto:
      type: object
      title: Component
      description: Component of a car
      required:
        - id
        - componentType
        - information
      properties:
        id:
          type: integer
          format: int64
          description: Id of the component
          example: 1
        componentType:
          $ref: '#/components/schemas/CarComponentType'
        weight:
          type: number
          description: Weight of the component
          example: 50.5
        information:
          type: string
          description: Specific information about component
          example: lightweight front wing v2 (black)

    ApplicationStatus:
      type: string
      description: Status of application
      enum:
        - pending
        - rejected
        - accepted

    ApplicationDto:
      type: object
      title: Application
      description: Application for becoming driver
      required:
        - id
        - name
        - surname
        - fillingOutDate
        - email
      properties:
        id:
          type: integer
          description: Id of the application
          example: 1
          format: int64
        name:
          type: string
          description: Name of the person
          example: Max
        surname:
          type: string
          description: Surname of the person
          example: Verstappen
        birthday:
          type: string
          description: Date of birth
          example: 09-30-1997
          format: date
        email:
          type: string
          description: Email address of the person
        fillingOutDate:
          type: string
          description: Date of filling out the application
          example: 09-30-1997
          format: date
        status:
          $ref: '#/components/schemas/ApplicationStatus'
  responses:
    Unexpected:
      description: Unexpected error
      content:
        application/json:
          schema:
            type: object
            title: Unexpected
            properties:
              message:
                type: string

paths:
  /notification:
    post:
      tags:
        - NotificationService
      summary: Creates and sends notification(s)
      operationId: notify
      requestBody:
        required: true
        description: Request body with receiver and message for new notification
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NotificationDto'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfirmationDto'
        default:
          $ref: '#/components/responses/Unexpected'
  /notification/component:
    post:
      tags:
        - NotificationService
      summary: Creates and sends notification(s) about new component
      operationId: notifyNewComponent
      requestBody:
        required: true
        description: Request body with receiver and car component for new notification
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CarComponentNotificationDto'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfirmationDto'
        default:
          $ref: '#/components/responses/Unexpected'
  /notification/application/new:
    post:
      tags:
        - NotificationService
      summary: Creates and sends notification(s)
      operationId: notifyNewApplication
      requestBody:
        required: true
        description: Request body with receiver and message for new notification
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplicationNotificationDto'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfirmationDto'
        default:
          $ref: '#/components/responses/Unexpected'
  /notification/application/status:
    post:
      tags:
        - NotificationService
      summary: Creates and sends notification
      operationId: notifyApplicationStatusChange
      requestBody:
        required: true
        description: Request body with receiver and message for new notification
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplicationNotificationDto'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfirmationDto'
        default:
          $ref: '#/components/responses/Unexpected'

