openapi: 3.0.0
info:
  title: Deviation API - ValueStreamer
  version: "3.0"
  description: "This is the specification of the REST interface for the deviation API."
servers:
  - url: https://api-tenant.valuestreamer.de/api
security:
  - basicAuth: []
tags:
  - name: "Deviation"
    description: "Endpoints for fetching and updating deviations"
  - name: "Deviation: Description"
    description: "Endpoints for fetching and updating the data of the richtext input field 'description'."
  - name: "Meta: Team config"
    description: "Endpoints to retrieve the deviation configurations of the teams."
  - name: "Meta: Sys. admin"
    description: "Sys. admin endpoints to maintain the available deviation categories."
  - name: "Deviation: Work Safety"
    description: "Endpoints to retrieve the configuration of additional work safety specific fields in a deviation."
paths:
  /exchange/deviations:
    get:
      tags:
        - "Deviation"
      summary: "Retrieve a collection of deviations by team"
      description: "Returns a list of deviations, ordered by creation date (desc)."
      parameters:
        - in: "query"
          name: "team"
          description: "UUID of the team to fetch the deviations for."
          required: true
          schema:
            type: "string"
            format: "uuid"
        - in: "query"
          name: "status"
          description: "Filters deviation by status (active/closed)."
          required: true
          schema:
            type: string
            enum: [ALL, ACTIVE, CLOSED]
            default: ACTIVE
        - in: "query"
          name: "level"
          description: "Filters by deviation level. A deviation can be either a single deviation, a combined parent deviation, or the child of a combined deviation. The levels can be added as comma-separated list, e.g. SINGLE,COMBINED."
          required: true
          schema:
            type: string
            enum: [ ALL, SINGLE, COMBINED, CHILD ]
            default: SINGLE
        - in: "query"
          name: "countermeasures"
          description: "Filters by existing countermeasures."
          required: false
          schema:
            type: string
            enum: [WITHCOUNTERMEASURES, WITHOUTCOUNTERMEASURES]
        - in: "query"
          name: "page"
          description: "page id, starting by 1"
          required: true
          schema:
            type: "integer"
            maximum: 50
      responses:
        '200':
          description: OK
          content:
            application/vs.v3.0+json:
              schema:
                allOf:
                  - properties:
                      page:
                        $ref: '#/components/schemas/Page'
                      entries:
                        type: array
                        items:
                          $ref: '#/components/schemas/DeviationExcerptWithSourceEntity'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
    post:
      tags:
        - "Deviation"
      summary: "Create a deviation"
      requestBody:
        required: true
        content:
          "application/vs.v2.0+json":
            schema:
              allOf:
                - $ref: '#/components/schemas/DeviationCreateRequestBodyWithSourceEntity'
                - required:
                    - "category"
                    - "title"
                    - "deviationType"
                    - "duration"
                    - "frequency"
                    - "responsibleTeam"
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/DeviationCreateRequestBody'
                - required:
                    - "category"
                    - "title"
                    - "deviationType"
                    - "duration"
                    - "frequency"
                    - "responsibleTeam"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeviationDetails'
            "application/vs.v2.0+json":
              schema:
                $ref: '#/components/schemas/DeviationDetailsWithSourceEntity'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /exchange/deviations/{id}:
    get:
      tags:
        - "Deviation"
      summary: "Retrieve a specific deviation."
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation."
          required: true
          schema:
            type: "string"
            format: "uuid"
        - in: "query"
          name: "include"
          description: "Query param can be added to the URL optionally. If added, the related countermeasures are included to the response."
          required: false
          schema:
            type: string
            enum: [ COUNTERMEASURES ]
      responses:
        '200':
          description: OK
          content:
            application/vs.v3.0+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/DeviationDetailsWithSourceEntityAndWorkSafety'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    put:
      tags:
        - "Deviation"
      summary: "Update a deviation"
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation."
          required: true
          schema:
            type: "string"
            format: "uuid"
      requestBody:
        required: true
        content:
          application/vs.v3.0+json:
            schema:
              allOf:
                - $ref: '#/components/schemas/DeviationUpdateRequestBodyWithSourceEntity'
                - required:
                    - "category"
                    - "closed"
                    - "title"
                    - "deviationType"
                    - "duration"
                    - "frequency"
      responses:
        '200':
          description: OK
          content:
            application/vs.v3.0+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/DeviationDetailsWithSourceEntityAndWorkSafety'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - "Deviation"
      summary: "Delete a deviation."
      description: "Only single or combined parent deviations can be deleted directly. Child deviations are deleted, when the parent deviation is deleted."
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation."
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        '204':
          description: "Record deleted"
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /exchange/deviations/{id}/description:
    summary: "Get the data of the richtext input field 'description' of the deviation."
    get:
      tags:
        - "Deviation: Description"
      summary: "Get the description."
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation."
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        '200':
          description: OK
          content:
            text/html:
              schema:
                $ref: '#/components/schemas/Description'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    put:
      tags:
        - "Deviation: Description"
      summary: "Update the description."
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation."
          required: true
          schema:
            type: "string"
            format: "uuid"
      requestBody:
        required: true
        description: "Description of deviation as HTML string"
        content:
          text/html:
            schema:
              $ref: '#/components/schemas/Description'
      responses:
        '200':
          description: OK
          content:
            text/html:
              schema:
                $ref: '#/components/schemas/Description'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ConflictOpenCountermeasures'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /exchange/deviation-categories:
    get:
      tags:
        - "Meta: Sys. admin"
      summary: "Get all available deviation categories on the tenant"
      parameters:
        - in: "query"
          name: "active"
          description: "Filters the categories by status active, inactive, or includes all categories."
          required: false
          schema:
            type: string
            enum: [ ALL, ACTIVE, INACTIVE ]
            default: ALL
        - in: "query"
          name: "category-type"
          description: "Filters the categories by core or includes all categories."
          required: false
          schema:
            type: string
            enum: [ ALL, CORE ]
            default: ALL
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CategoryWithTeams'
            application/vs.v2.0+json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CategoryWithTeamsV2'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
    post:
      tags:
        - "Meta: Sys. admin"
      summary: "Create a deviation category"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/CategoryCreateRequestBody'
                - required:
                    - "active"
                    - "name"
                    - "teams"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CategoryWithTeams'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /exchange/deviation-categories/{id}:
    get:
      tags:
        - "Meta: Sys. admin"
      summary: "Retrieve a specific deviation category."
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation category."
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/CategoryWithTeams'
            application/vs.v2.0+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/CategoryWithTeamsV2'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    put:
      tags:
        - "Meta: Sys. admin"
      summary: "Update a deviation category"
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation category."
          required: true
          schema:
            type: "string"
            format: "uuid"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/CategoryCreateRequestBody'
                - required:
                    - "active"
                    - "name"
                    - "teams"
          application/vs.v2.0+json:
            schema:
              allOf:
                - $ref: '#/components/schemas/CategoryCreateRequestBody'
                - required:
                    - "active"
                    - "name"
                    - "teams"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/CategoryWithTeams'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ConflictDeleted'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - "Meta: Sys. admin"
      summary: "Delete a deviation category."
      description: "Deletes the category. If a category is deleted, this category can also no longer be selected when creating a new deviation. For already created (and archived) deviations, the category remains. "
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the deviation category."
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        '204':
          description: "Record deleted"
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /exchange/teams/{id}/deviation-config:
    get:
      tags:
        - "Meta: Team config"
      summary: "Get the deviation configuration for a specific team"
      parameters:
        - in: "path"
          name: "id"
          description: "UUID of the team"
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeviationTeamConfigDetails'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /exchange/worksafety-config:
    get:
      tags:
        - "Deviation: Work Safety"
      summary: "Get configurations of work safety"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExWorkSafetyConfigDto'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
  schemas:

    Category:
      description: 'A category must be assigned to a deviation.'
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: "UUID"
        active:
          type: boolean
          default: true
          description: 'Indicates whether the category is activated or not'
        deleted:
          type: boolean
          default: false
          description: 'Indicates whether the category is deleted or not'
        name:
          type: array
          description: "The name of the category in all languages."
          items:
            type: object
            properties:
              language:
                $ref: '#/components/schemas/Languages'
              name:
                type: string
                description: "Translation"
                example: "My category name"
    CategoryWithTeams:
      description: 'A category must be assigned to a deviation.'
      allOf:
        - $ref: '#/components/schemas/Category'
        - type: object
          properties:
            teams:
              type: array
              description: "List of team IDs in which the category is available."
              items:
                type: string
                format: uuid

    CategoryWithTeamsV2:
      description: 'A category must be assigned to a deviation.'
      allOf:
        - $ref: '#/components/schemas/CategoryWithTeams'
        - type: object
          properties:
            coreCategory:
              type: boolean
              description: 'Indicates whether the category is core or not'
            coreCategoryType:
              type: string
              enum: [ WORKSAFETY ]
              description: 'is null, if coreCategory is false'
    CategoryCreateRequestBody:
      description: ''
      type: object
      properties:
        active:
          type: boolean
          default: true
          description: 'Indicates whether the category is activated or not'
        name:
          type: array
          description: "The name of the category in all languages"
          items:
            type: object
            properties:
              language:
                $ref: '#/components/schemas/Languages'
              name:
                type: string
                description: "Translation"
                example: "My category name"
        teams:
          type: array
          description: "List of teams IDs in which the category is available."
          items:
            type: string
            format: uuid
    # Schema for error response body
    Error:
      description: "Common error response object returned if a request failed."
      type: object
      properties:
        errorId:
          type: string
          description: "Unique error ID for this error response"
        errorMessage:
          type: string
    Description:
      type: string
      maxLength: 4294967295
      description: 'Description shown in the richtext editor of a deviation as HTML string.'
      example: "<p>Description of <b>Deviation A</b>.</p>"
    DeviationType:
      type: string
      enum: [PROBLEM, ERROR]
      nullable: false
    DeviationTypeV3:
      type: string
      enum: [ NEAR_MISS, ACCIDENT, PROBLEM, ERROR ]
      default: NEAR_MISS
      nullable: false
    Languages:
      type: string
      enum: [DE,EN,CS,CZ,ES-MX,FR,HU,PL,PT-BR,TH]
      example: "EN"
    Page:
      type: object
      readOnly: true
      properties:
        page:
          type: integer
          description: "Number of the current page"
        elementsOnPage:
          type: integer
          description: "Number of elements on the current page"
        elementsPerPage:
          type: integer
          description: "Number of elements per page"
        totalPages:
          type: integer
          description: "Number of all pages"
        totalElements:
          type: integer
          description: "Number of all elements"
    DeviationExcerpt:
      type: "object"
      properties:
        id:
          type: string
          format: uuid
          description: "UUID of the deviation"
          readOnly: true
        category:
          type: string
          format: 'uuid'
          description: "UUID of the corresponding category"
        createdBy:
          type: string
          format: 'uuid'
          description: "UUID of the user that created the deviation."
          readOnly: true
        createdDate:
          type: string
          format: 'date'
          description: "Creation date."
          readOnly: true
        closed:
          type: boolean
          default: false
          description: "Indicates whether the deviation is active or closed."
        deviationType:
          $ref: '#/components/schemas/DeviationTypeV3'
        duration:
          type: number
          format: int
          description: "Indicates how long the deviations lasted. Value must be greater than 0. Unit: minutes"
          nullable: false
        frequency:
          type: number
          format: int
          description: "Indicates how often the deviation occurred. Value must be greater than 0"
        responsibleTeam:
          type: string
          format: 'uuid'
          description: "UUID of the responsible team."
          nullable: false
        status:
          description: "Indicates whether the deviation is active or closed."
          type: string
          enum: [ACTIVE_WITH_COUNTERMEASURES, ACTIVE_WITHOUT_COUNTERMEASURES, CLOSED_WITH_COUNTERMEASURES, CLOSED_WITHOUT_COUNTERMEASURES]
        source:
          type: string
          description: "The deviations origin (e.g. KPI title, Weekly topic title, ..."
          readOnly: true
        title:
          type: string
          description: "Title of the deviation"
          minLength: 3
          maxLength: 255
          nullable: false
        level:
          type: string
          enum: [SINGLE, COMBINED, CHILD]
          description: "Indicates whether it is a single deviation, a combined parent or a child of a combined parent"
        combinedParentDeviation:
          type: object
          properties:
            isCombinedParentDeviation:
              type: boolean
              description: "Indicates whether this deviation is a combined parent deviation or not"
              default: true
              nullable: false
            childDeviations:
              type: array
              items:
                type: string
                format: uuid
          description: "When this deviation is a combined parent deviation and therefore isCombinedDeviation is TRUE, this property contains a list of id of the combined child deviations"
          nullable: false
        childDeviation:
          type: object
          properties:
            isChildDeviation:
              type: boolean
              description: "Indicates whether the deviation is a child of a combined deviation or not"
              default: false
              nullable: false
            parentDeviation:
              type: string
              format: uuid
              description: "When the deviation is a child and therefore isChildDeviation is TRUE, this field contains the id of the parent combined deviation. Otherwise, it is null"
              default: null
              nullable: true
    DeviationWorkSafety:
      type: "object"
      properties:
        textfield_long_1:
          type: string
          nullable: true
        textfield_long_2:
          type: string
          nullable: true
        textfield_long_3:
          type: string
          nullable: true
        textfield_short_1:
          type: string
          nullable: true
        textfield_short_2:
          type: string
          nullable: true
        textfield_short_3:
          type: string
          nullable: true
        checkbox_1:
          type: boolean
          nullable: true
        checkbox_2:
          type: boolean
          nullable: true
        checkbox_3:
          type: boolean
          nullable: true
        checkbox_4:
          type: boolean
          nullable: true
        checkbox_5:
          type: boolean
          nullable: true
        checkbox_6:
          type: boolean
          nullable: true
        dropdown_1:
          type: string
          format: uuid
          nullable: true
        dropdown_2:
          type: string
          format: uuid
          nullable: true
        dropdown_3:
          type: string
          format: uuid
          nullable: true
        dropdown_4:
          type: string
          format: uuid
          nullable: true
        dropdown_5:
          type: string
          format: uuid
          nullable: true
        dropdown_6:
          type: string
          format: uuid
          nullable: true
    DeviationExcerptWithSourceEntity:
      allOf:
        - $ref: '#/components/schemas/DeviationExcerpt'
        - type: object
          properties:
            sourceEntity:
              $ref: '#/components/schemas/SourceEntity'
            worksafety:
              $ref: '#/components/schemas/DeviationWorkSafety'

    DeviationCreateRequestBody:
      type: "object"
      properties:
        category:
          type: string
          format: 'uuid'
          description: "UUID of the corresponding category"
        deviationType:
          $ref: '#/components/schemas/DeviationType'
        duration:
          type: number
          format: int
          description: "Indicates how long the deviation lasted. Value must be greater than 0. Unit: minutes"
          nullable: false
        frequency:
          type: number
          format: int
          description: "Indicates how often the deviation occurred. Value must be greater than 0"
        responsibleTeam:
          type: string
          format: 'uuid'
          description: "UUID of the responsible team."
          nullable: false
        title:
          type: string
          description: "Title of the deviation"
          minLength: 3
          maxLength: 255
          nullable: false
    DeviationCreateRequestBodyWithSourceEntity:
      allOf:
        - $ref: '#/components/schemas/DeviationCreateRequestBody'
        - type: object
          properties:
            sourceEntity:
              $ref: '#/components/schemas/SourceEntity'
    DeviationUpdateRequestBody:
      type: "object"
      properties:
        category:
          type: string
          format: 'uuid'
          description: "UUID of the corresponding category. Only changeable for single deviations."
        closed:
          type: boolean
          default: false
          description: "Indicates whether the deviation is active or closed. Only changeable for single or parent deviations."
        deviationType:
          $ref: '#/components/schemas/DeviationTypeV3'
        duration:
          type: number
          format: int
          description: "Indicates how long the deviation lasted. Value must be greater than 0. Unit: minutes. Not changeable for parent deviations."
          nullable: false
        frequency:
          type: number
          format: int
          description: "Indicates how often the deviation occurred. Value must be greater than 0. Not changeable for parent deviations."
        title:
          type: string
          description: "Title of the deviation"
          minLength: 3
          maxLength: 255
          nullable: false
    DeviationUpdateRequestBodyWithSourceEntity:
      allOf:
        - $ref: '#/components/schemas/DeviationUpdateRequestBody'
        - type: object
          properties:
            sourceEntity:
              $ref: '#/components/schemas/SourceEntity'
    DeviationDetails:
      type: "object"
      properties:
        id:
          type: string
          format: uuid
          description: "UUID of the deviation."
          readOnly: true
        category:
          type: string
          format: 'uuid'
          description: "UUID of the corresponding category"
        createdBy:
          type: string
          format: 'uuid'
          description: "UUID of the user that created the deviation."
          readOnly: true
        createdDate:
          type: string
          format: 'date'
          description: "Creation date."
          readOnly: true
        closed:
          type: boolean
          default: false
          description: "Indicates whether the deviation is active or closed."
        closedOn:
          type: string
          format: 'date'
          description: "Closing date."
          readOnly: true
          nullable: true
          example: null
        duration:
          type: number
          format: int
          description: "Indicates how long the deviation lasted. Unit: minutes"
          nullable: false
        frequency:
          type: number
          format: int
          description: "Indicates how often the deviation occurred"
        modifiedBy:
          type: string
          format: 'uuid'
          description: "UUID of the user who last modified the record"
          readOnly: true
          nullable: true
        modifiedDate:
          type: string
          format: 'date'
          description: ""
          readOnly: true
          nullable: true
        responsibleTeam:
          type: string
          format: 'uuid'
          description: "UUID of the responsible team."
          nullable: false
        status:
          description: "Indicates whether the deviation is active or closed."
          type: string
          enum: [ACTIVE-WITH-COUNTERMEASURES, ACTIVE-WITHOUT-COUNTERMEASURES, CLOSED]
        source:
          type: string
          description: "The deviations origin (e.g. KPI title, Weekly topic title, ..."
          readOnly: true
        title:
          type: string
          description: "Title of the deviation"
          maxLength: 255
          nullable: false
        level:
          type: string
          enum: [SINGLE, COMBINED, CHILD]
          description: "Indicates whether it is a single deviation, a combined parent or a child of a combined parent"
        combinedDeviation:
          type: object
          properties:
            isCombinedDeviation:
              type: boolean
              description: "Indicates whether this deviation is a combined parent deviation or not"
              default: true
              nullable: false
            childDeviations:
              type: array
              items:
                type: string
                format: uuid
          description: "When this deviation is a combined parent deviation and therefore isCombinedDeviation is TRUE, this property contains a list of id of the combined child deviations"
          nullable: false
        childDeviation:
          type: object
          properties:
            isChildDeviation:
              type: boolean
              description: "Indicates whether the deviation is a child of a combined deviation or not"
              default: false
              nullable: false
            parentDeviation:
              type: string
              format: uuid
              description: "When the deviation is a child and therefore isChildDeviation is TRUE, this field contains the id of the parent combined deviation. Otherwise, it is null"
              default: null
              nullable: true
        countermeasures:
          type: array
          items:
            $ref: '#/components/schemas/CountermeasureExcerpt'
    DeviationDetailsWithSourceEntity:
      allOf:
        - $ref: '#/components/schemas/DeviationDetails'
        - type: object
          properties:
            deviationType:
              $ref: '#/components/schemas/DeviationType'
        - type: object
          properties:
            sourceEntity:
              $ref: '#/components/schemas/SourceEntity'
    DeviationTeamConfigDetails:
      type: "object"
      properties:
        categories:
          type: array
          items:
            $ref: '#/components/schemas/Category'
    CountermeasureExcerpt:
      type: "object"
      description: "Contains details of related countermeasures"
      properties:
        id:
          type: string
          format: uuid
          description: "UUID of the countermeasure."
          readOnly: true
        progress:
          type: string
          enum: [PLAN, DO, CHECK, ACT]
          description: "Progress of the countermeasure. Either PLAN, DO, CHECK or ACT"
          nullable: false
        responsibleTeam:
          type: string
          format: 'uuid'
          description: "UUID of the responsible team."
          nullable: false
        status:
          description: "Status of the countermeasure. 1=green, 2=yellow, 3=red."
          type: string
          enum: [1,2,3]
          nullable: false
        title:
          type: string
          description: "Title of the countermeasure"
          maxLength: 255
          nullable: false
        type:
          description: "Type of the countermeasure. Either PDCA or A3"
          type: string
          enum: [PDCA,A3]
          nullable: false
        createdDate:
          type: string
          format: 'date'
          description: "Creation date."
          readOnly: true
    SourceEntity:
      type: object
      description: "The deviations origin."
      nullable: true
      properties:
        type:
          type: string
          enum: [KPI, LIST, WEEKLYTOPIC, MEETINGATTENDANCE, PROCESSACTIVITY, TASK]
        id:
          type: string
          format: uuid
        name:
          type: string
          readOnly: true
    DeviationDetailsWithSourceEntityAndWorkSafety:
      allOf:
        - $ref: '#/components/schemas/DeviationDetailsWithSourceEntity'
        - type: object
          properties:
            deviationType:
              $ref: '#/components/schemas/DeviationTypeV3'
        - type: object
          properties:
            worksafety:
              $ref: '#/components/schemas/ExDeviationWorkSafetyDto'
    ExWorkSafetyConfigDto:
      type: object
      properties:
        textfield_long_1:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        textfield_long_2:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        textfield_long_3:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        textfield_short_1:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        textfield_short_2:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        textfield_short_3:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        dropdowm_1:
          $ref: '#/components/schemas/ExDropdownFieldDto'
        dropdowm_2:
          $ref: '#/components/schemas/ExDropdownFieldDto'
        dropdowm_3:
          $ref: '#/components/schemas/ExDropdownFieldDto'
        dropdowm_4:
          $ref: '#/components/schemas/ExDropdownFieldDto'
        dropdowm_5:
          $ref: '#/components/schemas/ExDropdownFieldDto'
        dropdowm_6:
          $ref: '#/components/schemas/ExDropdownFieldDto'
        checkbox_1:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        checkbox_2:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        checkbox_3:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        checkbox_4:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        checkbox_5:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        checkbox_6:
          $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
    ExDeviationWorkSafetyDto:
      type: "object"
      properties:
        textfield_long_1:
          type: string
          nullable: true
        textfield_long_2:
          type: string
          nullable: true
        textfield_long_3:
          type: string
          nullable: true
        textfield_short_1:
          type: string
          nullable: true
        textfield_short_2:
          type: string
          nullable: true
        textfield_short_3:
          type: string
          nullable: true
        checkbox_1:
          type: boolean
          nullable: true
        checkbox_2:
          type: boolean
          nullable: true
        checkbox_3:
          type: boolean
          nullable: true
        checkbox_4:
          type: boolean
          nullable: true
        checkbox_5:
          type: boolean
          nullable: true
        checkbox_6:
          type: boolean
          nullable: true
        dropdown_1:
          type: string
          format: 'uuid'
          nullable: true
        dropdown_2:
          type: string
          format: 'uuid'
          nullable: true
        dropdown_3:
          type: string
          format: 'uuid'
          nullable: true
        dropdown_4:
          type: string
          format: 'uuid'
          nullable: true
        dropdown_5:
          type: string
          format: 'uuid'
          nullable: true
        dropdown_6:
          type: string
          format: 'uuid'
          nullable: true
    ExWorkSafetyFieldBaseDto:
      type: object
      properties:
        active:
          type: boolean
        names:
          type: object
          additionalProperties:
            type: string
        type:
          $ref: '#/components/schemas/ExWorkSafetyFieldTypeEnum'

    ExDropdownFieldDto:
      allOf:
        - $ref: '#/components/schemas/ExWorkSafetyFieldBaseDto'
        - type: object
          properties:
            options:
              type: array
              items:
                $ref: '#/components/schemas/ExDropdownOptionDto'

    ExDropdownOptionDto:
      type: object
      properties:
        id:
          type: string
          format: uuid
        fieldId:
          $ref: '#/components/schemas/ExWorkSafetyDropDownEnum'
        names:
          type: object
          additionalProperties:
            type: string
        orderId:
          type: integer

    ExWorkSafetyFieldTypeEnum:
      type: string
      enum:
        - TEXTFIELD_SHORT
        - TEXTFIELD_LONG
        - DROPDOWN
        - CHECKBOX

    ExWorkSafetyDropDownEnum:
      type: string
      enum:
        - DROPDOWN_1
        - DROPDOWN_2
        - DROPDOWN_3
        - DROPDOWN_4
        - DROPDOWN_5
        - DROPDOWN_6
  responses:
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Not authorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnsupportedMediaType:
      description: UnsupportedMediaType
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Conflict:
      description: "The entry cannot be updated. Possible reasons: 1) The deviation is already closed and therefore read only. 2) An attempt is made to close the deviation, but there are still open countermeasures."
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ConflictDeleted:
      description: "The entry cannot be updated because it has been deleted and is therefore read-only."
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ConflictOpenCountermeasures:
      description: "Error when trying to close a deviation, but the deviation has open countermeasures (progress NOT equals ACT)"
      content:
        application/json:
          schema:
            type: object
            properties:
              errorId:
                type: string
                description: "Unique error ID for this error response"
              errorMessage:
                type: string
              openCountermeasures:
                $ref: '#/components/schemas/CountermeasureExcerpt'
    UnprocessableEntity:
      description: "The request is rejected because the content violates a business rule. E.g.: Team ID does not exist."
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
