openapi: 3.0.0
info:
  title: WorkGroupPerson
  version: 2.0.0
  description: >
    A **WorkGroupPerson** represents the assignment of a person to a work group.

    Links a PersonOffice (person-office assignment) to a WorkGroup.


    Use this API to:

    - Assign a person to a job role, work phase, or homogeneous group

    - Find all people in a work group (filter by `work_group_id`)

    - Find all work groups a person belongs to (filter by `person_office_id`)


    Optionally, exposure time can be recorded (`time_spent_measure` +
    `unit_of_measure_id`).


    Supports historicization.
servers:
  - url: http://service.4hse.com/
security:
  - OAuth2: []
  - AccessToken: []
paths:
  /v2/work-group-person/index:
    post:
      summary: index
      operationId: indexWorkGroupPerson
      tags:
        - WorkGroupPersons
      description: |
        Returns a paginated list of person-work group assignments.

        Most useful filters:
        - `work_group_id`: all people in a specific work group
        - `person_office_id`: all work groups a person belongs to
        - `person_last_name`: search by person name
      requestBody:
        description: Parameters for searching
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkGroupPersonIndexParams"
            example:
              filter:
                work_group_id: 3a4b5c6d-7e8f-9012-abcd-ef3456789012
              per-page: 20
              page: 1
              sort: person_last_name
      responses:
        "200":
          description: List of person-work group assignments
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ViewWorkGroupPerson"
          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/work-group-person/create:
    post:
      summary: create
      operationId: createWorkGroupPerson
      tags:
        - WorkGroupPersons
      description: >
        Assigns a person to a work group.


        Requires `work_group_id` and `person_office_id`.

        The `work_group_person_id` is auto-generated if not provided.


        The person must be assigned to the same office as the work group (via
        PersonOffice).
      requestBody:
        description: Assignment to create
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkGroupPerson"
      responses:
        "201":
          description: Person assigned to work group successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkGroupPerson"
  /v2/work-group-person/view/{id}:
    get:
      summary: view
      operationId: viewWorkGroupPerson
      tags:
        - WorkGroupPersons
      description: Retrieves a single assignment by its ID.
      parameters:
        - name: id
          in: path
          description: The work_group_person_id to retrieve.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Assignment found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ViewWorkGroupPerson"
        "404":
          description: Assignment not found
  /v2/work-group-person/update/{id}:
    put:
      summary: update
      operationId: updateWorkGroupPerson
      tags:
        - WorkGroupPersons
      description: Updates an existing assignment.
      parameters:
        - name: id
          in: path
          description: The work_group_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/WorkGroupPerson"
      responses:
        "200":
          description: Assignment updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkGroupPerson"
        "404":
          description: Assignment not found
  /v2/work-group-person/delete/{id}:
    delete:
      summary: delete
      operationId: deleteWorkGroupPerson
      tags:
        - WorkGroupPersons
      description: |
        Deletes a person-work group assignment.

        If `force=false` (default), the response lists child entities.
        If `force=true`, the assignment and related entities are deleted.
      parameters:
        - name: id
          in: path
          description: The work_group_person_id to delete.
          required: true
          schema:
            type: string
            format: uuid
        - name: force
          in: query
          description: If true, deletes the assignment and all child entities.
          schema:
            type: boolean
            default: false
      responses:
        "204":
          description: Assignment deleted successfully
        "400":
          description: Preview of entities that would be deleted (returned when force=false)
components:
  schemas:
    WorkGroupPerson:
      type: object
      required:
        - work_group_id
        - person_office_id
      properties:
        work_group_person_id:
          type: string
          format: uuid
          description: Unique identifier. Auto-generated if not provided.
        work_group_id:
          type: string
          format: uuid
          description: The work group. Pass the `work_group_id` from the WorkGroup API.
        person_office_id:
          type: string
          format: uuid
          description: The person-office assignment. Pass the `person_office_id` from the
            PersonOffice API. The person must be assigned to the same office as
            the work group.
        time_spent_measure:
          type: string
          maxLength: 255
          description: Exposure time value. If specified, `unit_of_measure_id` is also
            required.
        unit_of_measure_id:
          type: string
          format: uuid
          description: Unit of measure for the exposure time. Required if
            `time_spent_measure` is set.
    ViewWorkGroupPerson:
      type: object
      properties:
        work_group_person_id:
          type: string
          format: uuid
        work_group_id:
          type: string
          format: uuid
        person_office_id:
          type: string
          format: uuid
        time_spent_measure:
          type: string
        unit_of_measure_id:
          type: string
          format: uuid
        person_id:
          type: string
          format: uuid
          description: The person ID.
        person_code:
          type: string
          description: Employee code.
        person_first_name:
          type: string
        person_last_name:
          type: string
        person_is_employee:
          type: boolean
        person_is_external:
          type: boolean
        work_group_code:
          type: string
        work_group_name:
          type: string
        work_group_type:
          type: string
          enum:
            - WORK_PLACE
            - HGROUP
            - JOB
        unit_of_measure_code:
          type: string
        unit_of_measure_name:
          type: string
        office_id:
          type: string
          format: uuid
        office_name:
          type: string
        office_code:
          type: string
        project_id:
          type: string
          format: uuid
        project_name:
          type: string
        project_type:
          type: string
          enum:
            - safety
            - template
        owned_active:
          type: boolean
          nullable: true
          description: Whether this assignment is currently active.
        parent_active:
          type: boolean
          nullable: true
          description: Whether the parent entities are currently active.
    WorkGroupPersonIndexParams:
      type: object
      properties:
        filter:
          $ref: "#/components/schemas/ViewWorkGroupPerson"
        per-page:
          type: integer
          minimum: 1
          default: 100
        page:
          type: integer
          minimum: 1
          default: 1
        sort:
          type: string
          enum:
            - work_group_code
            - work_group_name
            - work_group_type
            - person_code
            - person_first_name
            - person_last_name
        history:
          type: boolean
          description: If true, includes historicized entries.
      example:
        filter:
          work_group_id: 3a4b5c6d-7e8f-9012-abcd-ef3456789012
        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
