openapi: 3.0.0
info:
  title: WorkGroupEntity
  version: 2.0.0
  description: >
    A **WorkGroupEntity** represents the assignment of a resource (equipment,
    work environment,

    or substance) to a work group.


    The `entity_id` field is the resource ID and the `entity_type` specifies its
    type:

    - `EQUIPMENT`: an equipment item (`office_equipment_id`)

    - `WORK_ENVIRONMENT`: a work environment (`office_work_environment_id`)

    - `SUBSTANCE`: a substance (`office_substance_id`)


    Use this API to:

    - Assign equipment, work environments, or substances to a work group

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

    - Find all work groups a resource belongs to (filter by `entity_id`)


    The combination of `entity_id` + `work_group_id` must be unique.


    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-entity/index:
    post:
      summary: index
      operationId: indexWorkGroupEntity
      tags:
        - WorkGroupEntities
      description: >
        Returns a paginated list of resource-work group assignments.


        Most useful filters:

        - `work_group_id`: all resources in a specific work group

        - `entity_id`: all work groups a resource belongs to

        - `entity_type`: filter by resource type (`EQUIPMENT`,
        `WORK_ENVIRONMENT`, `SUBSTANCE`)
      requestBody:
        description: Parameters for searching
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkGroupEntityIndexParams"
            example:
              filter:
                work_group_id: 3a4b5c6d-7e8f-9012-abcd-ef3456789012
                entity_type: EQUIPMENT
              per-page: 20
              page: 1
              sort: entity_name
      responses:
        "200":
          description: List of resource-work group assignments
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ViewWorkGroupEntity"
          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-entity/create:
    post:
      summary: create
      operationId: createWorkGroupEntity
      tags:
        - WorkGroupEntities
      description: |
        Assigns a resource to a work group.

        Requires `work_group_id`, `entity_id`, and `entity_type`.
        The `work_group_entity_id` is auto-generated if not provided.

        What to pass as `entity_id` depends on the `entity_type`:
        - `EQUIPMENT`: pass the `office_equipment_id`
        - `WORK_ENVIRONMENT`: pass the `office_work_environment_id`
        - `SUBSTANCE`: pass the `office_substance_id`
      requestBody:
        description: Assignment to create
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkGroupEntity"
      responses:
        "201":
          description: Resource assigned to work group successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkGroupEntity"
  /v2/work-group-entity/view/{id}:
    get:
      summary: view
      operationId: viewWorkGroupEntity
      tags:
        - WorkGroupEntities
      description: Retrieves a single assignment by its ID.
      parameters:
        - name: id
          in: path
          description: The work_group_entity_id to retrieve.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Assignment found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ViewWorkGroupEntity"
        "404":
          description: Assignment not found
  /v2/work-group-entity/update/{id}:
    put:
      summary: update
      operationId: updateWorkGroupEntity
      tags:
        - WorkGroupEntities
      description: Updates an existing assignment.
      parameters:
        - name: id
          in: path
          description: The work_group_entity_id to update.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: Fields to update
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkGroupEntity"
      responses:
        "200":
          description: Assignment updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkGroupEntity"
        "404":
          description: Assignment not found
  /v2/work-group-entity/delete/{id}:
    delete:
      summary: delete
      operationId: deleteWorkGroupEntity
      tags:
        - WorkGroupEntities
      description: |
        Deletes a resource-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_entity_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:
    WorkGroupEntity:
      type: object
      required:
        - work_group_id
        - entity_id
        - entity_type
      properties:
        work_group_entity_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.
        entity_id:
          type: string
          format: uuid
          description: |
            The resource to assign. What to pass depends on `entity_type`:
            - `EQUIPMENT`: pass the `office_equipment_id`
            - `WORK_ENVIRONMENT`: pass the `office_work_environment_id`
            - `SUBSTANCE`: pass the `office_substance_id`
        entity_type:
          type: string
          enum:
            - EQUIPMENT
            - WORK_ENVIRONMENT
            - SUBSTANCE
          description: Type of resource being assigned.
        description:
          type: string
          maxLength: 4000
          nullable: true
          description: Optional description of the assignment.
        time_spent_measure:
          type: string
          maxLength: 50
          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.
    ViewWorkGroupEntity:
      type: object
      properties:
        work_group_entity_id:
          type: string
          format: uuid
        work_group_id:
          type: string
          format: uuid
        entity_id:
          type: string
          format: uuid
        entity_type:
          type: string
          enum:
            - EQUIPMENT
            - WORK_ENVIRONMENT
            - SUBSTANCE
        description:
          type: string
        time_spent_measure:
          type: string
        unit_of_measure_id:
          type: string
          format: uuid
        entity_name:
          type: string
          description: Name of the assigned resource.
        entity_code:
          type: string
          description: Code of the assigned resource.
        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.
    WorkGroupEntityIndexParams:
      type: object
      properties:
        filter:
          $ref: "#/components/schemas/ViewWorkGroupEntity"
        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
            - entity_name
            - entity_code
            - entity_type
        history:
          type: boolean
          description: If true, includes historicized entries.
      example:
        filter:
          work_group_id: 3a4b5c6d-7e8f-9012-abcd-ef3456789012
          entity_type: EQUIPMENT
        per-page: 100
        page: 1
        sort: entity_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
