openapi: 3.0.0
info:
  title: WorkEnvironment
  version: 2.0.0
  description: >
    A **WorkEnvironment** represents a work environment registered in an office.

    Examples: warehouse, chemical lab, welding area, underground site.


    Belongs to an office and can be subject to maintenance or check actions on
    the compliance schedule

    (ActionSubscription with `subscriber_type: WORK_ENVIRONMENT`).


    Use this API to:

    - Register work environments present in an office

    - Get the `office_work_environment_id` needed to create compliance schedule
    entries or certificates

    - Browse work environments for an office (filter by `office_id`)


    Supports historicization.
servers:
  - url: http://service.4hse.com/
security:
  - OAuth2: []
  - AccessToken: []
paths:
  /v2/work-environment/index:
    post:
      summary: index
      operationId: indexWorkEnvironment
      tags:
        - WorkEnvironments
      description: |
        Returns a paginated list of work environments.

        Most useful filters:
        - `office_id`: all work environments in a specific office
        - `name`: search by name
      requestBody:
        description: Parameters for searching work environments
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkEnvironmentIndexParams"
            example:
              filter:
                office_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
              per-page: 20
              page: 1
              sort: name
      responses:
        "200":
          description: List of work environments
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ViewWorkEnvironment"
          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-environment/create:
    post:
      summary: create
      operationId: createWorkEnvironment
      tags:
        - WorkEnvironments
      description: |
        Registers a new work environment in an office.

        Requires `office_id`, `project_id`, and `name`.
        The `office_work_environment_id` is auto-generated if not provided.
      requestBody:
        description: Work environment to register
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkEnvironment"
      responses:
        "201":
          description: Work environment registered successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkEnvironment"
  /v2/work-environment/view/{id}:
    get:
      summary: view
      operationId: viewWorkEnvironment
      tags:
        - WorkEnvironments
      description: Retrieves a single work environment by its ID.
      parameters:
        - name: id
          in: path
          description: The office_work_environment_id to retrieve.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Work environment found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ViewWorkEnvironment"
        "404":
          description: Work environment not found
  /v2/work-environment/update/{id}:
    put:
      summary: update
      operationId: updateWorkEnvironment
      tags:
        - WorkEnvironments
      description: Updates an existing work environment.
      parameters:
        - name: id
          in: path
          description: The office_work_environment_id to update.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: Fields to update
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WorkEnvironment"
      responses:
        "200":
          description: Work environment updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkEnvironment"
        "404":
          description: Work environment not found
  /v2/work-environment/delete/{id}:
    delete:
      summary: delete
      operationId: deleteWorkEnvironment
      tags:
        - WorkEnvironments
      description: >
        Deletes a work environment.


        If `force=false` (default), the response lists child entities.

        If `force=true`, the work environment and all related entities are
        deleted.
      parameters:
        - name: id
          in: path
          description: The office_work_environment_id to delete.
          required: true
          schema:
            type: string
            format: uuid
        - name: force
          in: query
          description: If true, deletes the work environment and all child entities.
          schema:
            type: boolean
            default: false
      responses:
        "204":
          description: Work environment deleted successfully
        "400":
          description: Preview of entities that would be deleted (returned when force=false)
components:
  schemas:
    WorkEnvironment:
      type: object
      required:
        - office_id
        - project_id
        - name
      properties:
        office_work_environment_id:
          type: string
          format: uuid
          description: >
            Unique identifier. Auto-generated if not provided. Used as
            `subscriber_id` (with `subscriber_type: WORK_ENVIRONMENT`) in the
            compliance schedule and as `resource_id` in certificates.
        office_id:
          type: string
          format: uuid
          description: The office this work environment belongs to. Pass the `office_id`.
        work_environment_id:
          type: string
          format: uuid
          description: Optional reference to a work environment model from the catalog
            (template).
        code:
          type: string
          maxLength: 45
          description: Identifier code.
        name:
          type: string
          maxLength: 255
          description: Name of the work environment.
        description:
          type: string
          nullable: true
          description: Optional description.
        project_id:
          type: string
          format: uuid
          description: The project (company). Pass the `project_id`.
    ViewWorkEnvironment:
      type: object
      properties:
        office_work_environment_id:
          type: string
          format: uuid
          description: Unique identifier. Used as `subscriber_id` (WORK_ENVIRONMENT) or
            `resource_id`.
        office_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        work_environment_id:
          type: string
          format: uuid
        code:
          type: string
        name:
          type: string
        description:
          type: string
        office_name:
          type: string
          description: Name of the office.
        project_name:
          type: string
          description: Name of the project.
        project_type:
          type: string
          enum:
            - safety
            - template
        category:
          type: string
          description: Work environment category (from catalog if linked).
        owned_active:
          type: boolean
          nullable: true
          description: Whether this work environment is currently active.
        parent_active:
          type: boolean
          nullable: true
          description: Whether the parent office is currently active.
    WorkEnvironmentIndexParams:
      type: object
      properties:
        filter:
          $ref: "#/components/schemas/ViewWorkEnvironment"
        per-page:
          type: integer
          minimum: 1
          default: 100
        page:
          type: integer
          minimum: 1
          default: 1
        sort:
          type: string
          enum:
            - code
            - name
            - office_name
            - project_name
        history:
          type: boolean
          description: If true, includes historicized entries.
      example:
        filter:
          office_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
        per-page: 100
        page: 1
        sort: 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
