openapi: 3.0.0
info:
  title: IncidentPerson
  version: 2.0.0
  description: |
    An **IncidentPerson** represents a person involved in an incident.
    Links an incident (Incident) to a person-office assignment (PersonOffice).

    Use this API to:
    - Register people involved in an incident
    - Find all people involved in an incident (filter by `office_incident_id`)
    - Find all incidents a person was involved in (filter by `person_office_id`)
    - Record sickness days per person (`days`)
servers:
  - url: http://service.4hse.com/
security:
  - OAuth2: []
  - AccessToken: []
paths:
  /v2/incident-person/index:
    post:
      summary: index
      operationId: indexIncidentPerson
      tags:
        - IncidentPersons
      description: |
        Returns a paginated list of people involved in incidents.

        Most useful filters:
        - `office_incident_id`: all people involved in a specific incident
        - `person_office_id`: all incidents a person was involved in
      requestBody:
        description: Parameters for searching
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/IncidentPersonIndexParams"
            example:
              filter:
                office_incident_id: 5c6d7e8f-9012-3456-abcd-ef5678901234
              per-page: 20
              page: 1
              sort: person_last_name
      responses:
        "200":
          description: List of involved people
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ViewIncidentPerson"
          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-person/create:
    post:
      summary: create
      operationId: createIncidentPerson
      tags:
        - IncidentPersons
      description: >
        Registers a person involved in an incident.


        Requires `office_incident_id`, `person_office_id`, `subtenant_id`
        (office_id), and `tenant_id` (project_id).

        The `office_incident_person_id` is auto-generated if not provided.
      requestBody:
        description: Involved person to register
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/IncidentPerson"
      responses:
        "201":
          description: Involved person registered successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/IncidentPerson"
  /v2/incident-person/view/{id}:
    get:
      summary: view
      operationId: viewIncidentPerson
      tags:
        - IncidentPersons
      description: Retrieves a single involved person by its ID.
      parameters:
        - name: id
          in: path
          description: The office_incident_person_id to retrieve.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Involved person found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ViewIncidentPerson"
        "404":
          description: Not found
  /v2/incident-person/update/{id}:
    put:
      summary: update
      operationId: updateIncidentPerson
      tags:
        - IncidentPersons
      description: Updates an existing involved person record.
      parameters:
        - name: id
          in: path
          description: The office_incident_person_id to update.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: Fields to update
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/IncidentPerson"
      responses:
        "200":
          description: Updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/IncidentPerson"
        "404":
          description: Not found
  /v2/incident-person/delete/{id}:
    delete:
      summary: delete
      operationId: deleteIncidentPerson
      tags:
        - IncidentPersons
      description: Deletes an involved person record.
      parameters:
        - name: id
          in: path
          description: The office_incident_person_id to delete.
          required: true
          schema:
            type: string
            format: uuid
        - name: force
          in: query
          description: If true, deletes the record.
          schema:
            type: boolean
            default: false
      responses:
        "204":
          description: Deleted successfully
        "400":
          description: Preview of affected entities (returned when force=false)
components:
  schemas:
    IncidentPerson:
      type: object
      required:
        - office_incident_id
        - person_office_id
        - tenant_id
        - subtenant_id
      properties:
        office_incident_person_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.
        person_office_id:
          type: string
          format: uuid
          maxLength: 50
          description: The involved person. Pass the `person_office_id` from the
            PersonOffice API.
        code:
          type: string
          maxLength: 50
          nullable: true
          description: Identifier code.
        description:
          type: string
          nullable: true
          description: Description of the person's involvement.
        days:
          type: integer
          nullable: true
          description: Number of sickness days for this person due to the incident.
        tenant_id:
          type: string
          format: uuid
          maxLength: 50
          description: The project (company). Pass the `project_id`.
        subtenant_id:
          type: string
          format: uuid
          maxLength: 50
          description: The office. Pass the `office_id`.
    ViewIncidentPerson:
      type: object
      properties:
        office_incident_person_id:
          type: string
          format: uuid
        office_incident_id:
          type: string
          format: uuid
        person_office_id:
          type: string
          format: uuid
        code:
          type: string
        description:
          type: string
        days:
          type: integer
        tenant_id:
          type: string
          format: uuid
        subtenant_id:
          type: string
          format: uuid
        person_id:
          type: string
          format: uuid
        person_code:
          type: string
          nullable: true
        person_first_name:
          type: string
        person_last_name:
          type: string
        person_is_employee:
          type: boolean
        incident_code:
          type: string
          nullable: true
        incident_name:
          type: string
        incident_date:
          type: string
          format: date
        incident_category:
          type: string
          nullable: true
        incident_status:
          type: string
          enum:
            - new
            - open
            - closed
        project_name:
          type: string
        project_type:
          type: string
          enum:
            - safety
            - template
        office_name:
          type: string
    IncidentPersonIndexParams:
      type: object
      properties:
        filter:
          $ref: "#/components/schemas/ViewIncidentPerson"
        per-page:
          type: integer
          minimum: 1
          default: 100
        page:
          type: integer
          minimum: 1
          default: 1
        sort:
          type: string
          enum:
            - person_first_name
            - person_last_name
            - person_code
            - incident_name
            - incident_date
            - office_name
      example:
        filter:
          office_incident_id: 5c6d7e8f-9012-3456-abcd-ef5678901234
        per-page: 100
        page: 1
        sort: person_last_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
