openapi: 3.1.0
info:
  title: UPowr Job Type API
  version: 1.0.0
servers:
  - url: /api/v1/job-types
security:
  - session: []
paths:
  /:
    post:
      summary: Create a new job type
      operationId: createJobType
      security:
        - session:
            - job-type:create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateJobType'
      responses:
        '201':
          $ref: '#/components/responses/CreateResponse'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '500':
          $ref: '#/components/responses/UnknownError'
  /{jobTypeId}:
    patch:
      summary: Update an existing Job Type
      operationId: updateJobType
      security:
        - session:
            - job-type:update
      parameters:
        - $ref: '#/components/parameters/jobTypeId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateJobType'
      responses:
        '200':
          $ref: '#/components/responses/SuccessResponse'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '500':
          $ref: '#/components/responses/UnknownError'
components:
  parameters:
    jobTypeId:
      name: jobTypeId
      in: path
      description: The Job Type id
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    CreateJobType:
      type: object
      properties:
        code:
          type: string
          description: The code of the Job Type.
        name:
          type: string
          description: The name of the Job Type.
        workflow:
          type: string
          enum:
            - inspection
            - installation
          description: The workflow of the Job Type.
        projectTypes:
          type: array
          items:
            type: string
            enum:
              - SALES
              - SERVICE
          description: A list of project types for filtering purposes.
        description:
          type: string
          description: A description of the Job Type.
      additionalProperties: false
      required:
        - code
        - name
        - workflow
        - projectTypes
    UpdateJobType:
      type: object
      properties:
        name:
          type: string
          description: The name of the Job Type.
        workflow:
          type: string
          enum:
            - inspection
            - installation
          description: The workflow of the Job Type.
        projectTypes:
          type: array
          items:
            type: string
            enum:
              - SALES
              - SERVICE
          description: A list of project types for filtering purposes.
        description:
          type: string
          description: A description of the Job Type.
      additionalProperties: false
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: Message describing the error.
        data:
          type: object
          properties:
            errors:
              type: array
              description: Information about the specific errors.
              items:
                type: object
                properties:
                  message:
                    type: string
                    description: Message describing the error related to the field.
      required:
        - message
  responses:
    CreateResponse:
      description: Job Type created successfully.
      content:
        application/json:
          schema:
            type: object
            properties:
              id:
                type: string
                description: The unique identifier for the newly created Job Type.
            required:
              - id
          examples:
            actionCompleted:
              description: Job Type created
              value:
                id: ABC123456DE
    SuccessResponse:
      description: Job Type actioned successfully.
      content:
        application/json:
          schema:
            type: object
            properties:
              ok:
                type: boolean
                description: Indicates whether the action was successful.
            required:
              - ok
          examples:
            updateSuccessful:
              description: Job Type actioned
              value:
                ok: true
    UnknownError:
      description: Unknown Error has occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            unknownError:
              summary: Unknown error occurred
              value:
                message: >-
                  Something's gone wrong, but we've been notified and we're
                  looking into it. If you have any questions, email
                  support@upowr.com.au with the error ID:
                  3fa85f64-5717-4562-b3fc-2c963f66afa7
    BadRequestError:
      description: Bad Request Error has occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            badRequestError:
              summary: Bad Request error occurred
              value:
                message: Invalid Job Type data
    UnauthorizedError:
      description: Unauthorized access. Valid authentication credentials are required.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            invalidCredentials:
              summary: Authentication failed due to invalid credentials
              value:
                message: Unauthorized
    NotFoundError:
      description: Job Type not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            notFoundError:
              summary: Failed to update job type due to invalid id
              value:
                message: 'Failed to update job type: invalid id provided'
  securitySchemes:
    session:
      type: oauth2
      description: Machine-to-Machine Authorization
      flows:
        clientCredentials:
          tokenUrl: https://id.core.upowr.cloud/oauth/token
          scopes:
            job-type:create: Create a job type
            job-type:update: Update a job type
