openapi: 3.0.0
info:
  title: OrgRole
  version: 2.0.0
  description: >
    An **OrgRole** represents a role in the company organization chart.

    Unlike office safety roles (Role/OfficeRole), these are organizational roles

    at company level.


    Examples: "Director", "Production Manager", "Quality Officer".


    Belongs to a project (not to an office). People are assigned to
    organizational

    roles via OrgPerson.


    Use this API to:

    - Define organizational chart roles

    - Browse available roles in a project (filter by `project_id`)


    Supports historicization.
servers:
  - url: http://service.4hse.com/
security:
  - OAuth2: []
  - AccessToken: []
paths:
  /v2/org-role/index:
    post:
      summary: index
      operationId: indexOrgRole
      tags:
        - OrgRoles
      description: |
        Returns a paginated list of organizational roles.

        Most useful filters:
        - `project_id`: all roles in a company
        - `name`: search by name
      requestBody:
        description: Parameters for searching
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrgRoleIndexParams"
            example:
              filter:
                project_id: b5a7d602-3fc9-4e2a-9d1a-6e5b4c8f7a01
              per-page: 20
              page: 1
              sort: name
      responses:
        "200":
          description: List of organizational roles
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ViewOrgRole"
          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/org-role/create:
    post:
      summary: create
      operationId: createOrgRole
      tags:
        - OrgRoles
      description: |
        Creates a new organizational role.

        Requires `name` and `project_id`.
        The `org_role_id` is auto-generated if not provided.
      requestBody:
        description: Role to create
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrgRole"
      responses:
        "201":
          description: Role created successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrgRole"
  /v2/org-role/view/{id}:
    get:
      summary: view
      operationId: viewOrgRole
      tags:
        - OrgRoles
      description: Retrieves a single organizational role by its ID.
      parameters:
        - name: id
          in: path
          description: The org_role_id to retrieve.
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Role found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ViewOrgRole"
        "404":
          description: Not found
  /v2/org-role/update/{id}:
    put:
      summary: update
      operationId: updateOrgRole
      tags:
        - OrgRoles
      description: Updates an existing organizational role.
      parameters:
        - name: id
          in: path
          description: The org_role_id to update.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: Fields to update
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrgRole"
      responses:
        "200":
          description: Updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrgRole"
        "404":
          description: Not found
  /v2/org-role/delete/{id}:
    delete:
      summary: delete
      operationId: deleteOrgRole
      tags:
        - OrgRoles
      description: >
        Deletes an organizational role.


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

        If `force=true`, the role and all related entities are deleted.
      parameters:
        - name: id
          in: path
          description: The org_role_id to delete.
          required: true
          schema:
            type: string
            format: uuid
        - name: force
          in: query
          description: If true, deletes the role and all child entities.
          schema:
            type: boolean
            default: false
      responses:
        "204":
          description: Deleted successfully
        "400":
          description: Preview of entities that would be deleted (returned when force=false)
components:
  schemas:
    OrgRole:
      type: object
      required:
        - name
        - project_id
      properties:
        org_role_id:
          type: string
          format: uuid
          description: Unique identifier. Auto-generated if not provided.
        code:
          type: string
          maxLength: 50
          description: Identifier code.
        name:
          type: string
          maxLength: 255
          description: Name of the organizational role.
        description:
          type: string
          nullable: true
          description: Optional description.
        project_id:
          type: string
          format: uuid
          description: The project (company). Pass the `project_id`.
    ViewOrgRole:
      type: object
      properties:
        org_role_id:
          type: string
          format: uuid
        code:
          type: string
        name:
          type: string
        description:
          type: string
        project_id:
          type: string
          format: uuid
        owned_active:
          type: boolean
          nullable: true
          description: Whether this role is currently active.
        parent_active:
          type: boolean
          nullable: true
          description: Whether the parent project is currently active.
    OrgRoleIndexParams:
      type: object
      properties:
        filter:
          $ref: "#/components/schemas/ViewOrgRole"
        per-page:
          type: integer
          minimum: 1
          default: 100
        page:
          type: integer
          minimum: 1
          default: 1
        sort:
          type: string
          enum:
            - code
            - name
        history:
          type: boolean
          description: If true, includes historicized entries.
      example:
        filter:
          project_id: b5a7d602-3fc9-4e2a-9d1a-6e5b4c8f7a01
        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
