openapi: 3.0.0
info:
  title: IncidentAction
  version: 2.0.0
  description: >
    An **IncidentAction** links an incident to a corrective or preventive
    action.

    It indicates that an action has been taken or must be taken in response to
    the incident.


    Use this API to:

    - Link corrective/preventive actions to an incident

    - Find all actions linked to an incident (filter by `office_incident_id`)

    - Find all incidents linked to an action (filter by `entity_id`)
servers:
  - url: http://service.4hse.com/
security:
  - OAuth2: []
  - AccessToken: []
paths:
  /v2/incident-action/index:
    post:
      summary: index
      operationId: indexIncidentAction
      tags:
        - IncidentActions
      description: |
        Returns a paginated list of incident-action links.

        Most useful filters:
        - `office_incident_id`: all actions linked to a specific incident
        - `entity_id` (action_id): all incidents linked to a specific action
        - `action_type`: filter by action type
      requestBody:
        description: Parameters for searching
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/IncidentActionIndexParams"
            example:
              filter:
                office_incident_id: 5c6d7e8f-9012-3456-abcd-ef5678901234
              per-page: 20
              page: 1
              sort: action_name
      responses:
        "200":
          description: List of incident-action links
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ViewIncidentAction"
          headers:
            X-Pagination-Current-Page:
              schema:
                type: integer
              description: Current page
            X-Pagination-Page-Count:
              schema:
                type: integer
              description: Total number of pages
            X-Pagination-Per-Page:
              schema:
                type: integer
              description: Number of items per page
            X-Pagination-Total-Count:
              schema:
                type: integer
              description: Total number of items
  /v2/incident-action/create:
    post:
      summary: create
      operationId: createIncidentAction
      tags:
        - IncidentActions
      description: >
        Links a corrective/preventive action to an incident.


        Requires `office_incident_id`, `entity_id` (the action_id),
        `entity_type` (always `ACTION`),

        `subtenant_id` (office_id), and `tenant_id` (project_id).

        The `office_incident_action_id` is auto-generated if not provided.
      requestBody:
        description: Incident-action link to create
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/IncidentAction"
      responses:
        "201":
          description: Action linked to incident successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/IncidentAction"
  /v2/incident-action/view/{id}:
    get:
      summary: view
      operationId: viewIncidentAction
      tags:
        - IncidentActions
      description: Retrieves a single incident-action link by its ID.
      parameters:
        - name: id
          in: path
          description: The office_incident_action_id to retrieve.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Incident-action link found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ViewIncidentAction"
        "404":
          description: Not found
  /v2/incident-action/update/{id}:
    put:
      summary: update
      operationId: updateIncidentAction
      tags:
        - IncidentActions
      description: Updates an existing incident-action link.
      parameters:
        - name: id
          in: path
          description: The office_incident_action_id to update.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: Fields to update
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/IncidentAction"
      responses:
        "200":
          description: Updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/IncidentAction"
        "404":
          description: Not found
  /v2/incident-action/delete/{id}:
    delete:
      summary: delete
      operationId: deleteIncidentAction
      tags:
        - IncidentActions
      description: Deletes an incident-action link.
      parameters:
        - name: id
          in: path
          description: The office_incident_action_id to delete.
          required: true
          schema:
            type: string
            format: uuid
        - name: force
          in: query
          description: If true, deletes the link.
          schema:
            type: boolean
            default: false
      responses:
        "204":
          description: Deleted successfully
        "400":
          description: Preview of affected entities (returned when force=false)
components:
  schemas:
    IncidentAction:
      type: object
      required:
        - office_incident_id
        - entity_type
        - entity_id
        - subtenant_id
        - tenant_id
      properties:
        office_incident_action_id:
          type: string
          format: uuid
          description: Unique identifier. Auto-generated if not provided.
        office_incident_id:
          type: string
          format: uuid
          maxLength: 50
          description: The incident. Pass the `office_incident_id` from the Incident API.
        entity_type:
          type: string
          maxLength: 50
          description: Always `ACTION`.
        entity_id:
          type: string
          format: uuid
          maxLength: 50
          description: The corrective/preventive action. Pass the `action_id` from the
            Action API.
        description:
          type: string
          nullable: true
          description: Optional description of why this action was linked (e.g. corrective
            action rationale).
        subtenant_id:
          type: string
          format: uuid
          maxLength: 50
          description: The office. Pass the `office_id`.
        tenant_id:
          type: string
          format: uuid
          maxLength: 50
          description: The project (company). Pass the `project_id`.
    ViewIncidentAction:
      type: object
      properties:
        office_incident_action_id:
          type: string
          format: uuid
        office_incident_id:
          type: string
          format: uuid
        entity_type:
          type: string
        entity_id:
          type: string
          format: uuid
        description:
          type: string
        subtenant_id:
          type: string
          format: uuid
        tenant_id:
          type: string
          format: uuid
        action_code:
          type: string
          description: Code of the linked action.
        action_name:
          type: string
          description: Name of the linked action.
        action_type:
          type: string
          enum:
            - TRAINING
            - MAINTENANCE
            - HEALTH
            - CHECK
            - PER
          description: Type of the linked action.
        incident_code:
          type: string
        incident_name:
          type: string
        incident_date:
          type: string
          format: date
        incident_category:
          type: string
        incident_status:
          type: string
          enum:
            - new
            - open
            - closed
        project_name:
          type: string
        project_type:
          type: string
          enum:
            - safety
            - template
        office_name:
          type: string
    IncidentActionIndexParams:
      type: object
      properties:
        filter:
          $ref: "#/components/schemas/ViewIncidentAction"
        per-page:
          type: integer
          minimum: 1
          default: 100
        page:
          type: integer
          minimum: 1
          default: 1
        sort:
          type: string
          enum:
            - action_code
            - action_name
            - action_type
            - incident_name
            - incident_date
            - office_name
      example:
        filter:
          office_incident_id: 5c6d7e8f-9012-3456-abcd-ef5678901234
        per-page: 100
        page: 1
        sort: action_name
  securitySchemes:
    OAuth2:
      type: oauth2
      flows:
        password:
          tokenUrl: https://auth.4hse.com/realms/4hse/protocol/openid-connect/token
          scopes: {}
    AccessToken:
      type: apiKey
      in: query
      name: access-token
