openapi: "3.0.3"
info:
  description: "Service to create and modify partitions of an e-Box and to manage users rights on partitions."
  version: "3.0"
  title: "Ebox Partition Management"
  contact:
    name: "eBoxIntegration"
    email: "eboxintegration@smals.be"
  license:
    name: "e-Box"
    url: "http://www.digitalbelgium.be"
servers:
  - url: /REST/ebox/enterprise/partitionManagement/v3
tags:
  - name: Monitoring
  - name: Partitions
  - name: Partition users
  - name: Receiver routing rules
  - name: Sender routing rules suggestions
security:
  - Oauth:
      [ 'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
        'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
        'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible',
        'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseuser',
        'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryuser',
        'scope:document:management:consult:ws-eboxrestentreprise:publicationsender',
        'scope:document:management:consult:ws-eboxrestentreprise:publicationweb',
        'scope:document:management:consult:ws-eboxrestentreprise:publicationmandate',
        'scope:document:management:consult:ws-eboxrestentreprise:monitoring',
        'scope:document:management:ws-eboxrestentreprise:eboxrepresentativepublication']
paths:
  /health:
    get:
      tags:
        - Monitoring
      summary: Check health of the service
      description: This resource is only available to supervision users
      operationId: checkHealth
      externalDocs:
        url: "https://www.belgif.be/specification/rest/api-guide/#health"
      responses:
        "200":
          description: The service is UP, DEGRADED, DOWN
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HealthStatus"
              examples:
                responseUp:
                  value:
                    {
                      "status": "UP"
                    }
                responseDegraded:
                  value:
                    {
                      "status": "DEGRADED"
                    }

        "503":
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            - 'scope:document:management:consult:ws-eboxrestentreprise:monitoring'
      x-oauth2-required-scopes: any

  /ebox/{enterpriseNumber}/routingRules:
    post:
      summary: "Create a routing rule"
      description: "Create a new routing rule for the enterprise ebox. A routing rule move messages to a target partition when the condition of the rule is met. You cannot create a routing rule with a condition already existing in an already created routing rule."
      tags:
        - "Receiver routing rules"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
      operationId: createRoutingRule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RoutingRuleToCreate"
      responses:
        200:
          description: "successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RoutingRuleCreatedResponse"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
    get:
      summary: "Retrieve all routing rules"
      description: "This endpoint is called to retrieve the list of routing rules used to determine if a message should be automatically routed to a partition based on some condition. The given list should be given in priority order in order. The first rule in the list with condition matching a message must be applied to move a message to the target partition. If another rule has condition that match the message but has a higher priority number, it should not be applied."
      tags:
        - "Receiver routing rules"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
          required: true
        - name: "partitionId"
          in: "query"
          schema:
            type: string
        - name: "messageTypeId"
          in: "query"
          schema:
            type: string
        - name: "senderApplicationId"
          in: "query"
          schema:
            type: string
        - name: "senderEnterpriseNumber"
          in: "query"
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
      operationId: getRoutingRules
      responses:
        200:
          description: "successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RoutingRulesToConsult"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any

  /ebox/{enterpriseNumber}/routingRules/{routingRuleId}:
    get:
      summary: "Get a routing rule"
      tags:
        - "Receiver routing rules"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "routingRuleId"
          in: "path"
          required: true
          schema:
            type: integer
      operationId: getRoutingRule
      responses:
        200:
          description: "successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RoutingRuleToConsult"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
    patch:
      summary: Change a routing rule priority
      tags:
        - "Receiver routing rules"
      operationId: patchRoutingRule
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
          required: true
        - name: "routingRuleId"
          in: "path"
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RoutingRuleToPatch"
      responses:
        204:
          description: "successful operation"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
    delete:
      summary: (soft)Delete a routing rule
      description: This endpoint is used to delete a routing rule. The routing rule is deleted through a soft-delete so we can keep track of routing rule ids used in the audit trails.
      tags:
        - "Receiver routing rules"
      operationId: deleteRoutingRule
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
          required: true
        - name: "routingRuleId"
          in: "path"
          required: true
          schema:
            type: integer
      responses:
        204:
          description: "successful operation"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any

  /ebox/{enterpriseNumber}/routingRulesSuggestions:
    get:
      tags:
        - "Receiver routing rules"
      operationId: getRoutingRuleSuggestions
      summary: "Get routing rule suggestions for the receiver"
      description: "Get all the routing rule suggestions for the receiver and the approval status of them. The suggested routing rules come from senders but the receiver is free to accept them or not. Once accepted, the routing rule must be created using the POST /ebox/{enterpriseNumber}/routingRules method."
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "messageTypeId"
          in: query
          required: false
          description: filter on a message type
          schema:
            type: string
        - name: "senderApplicationId"
          in: query
          required: false
          description: filter on a sender application
          schema:
            type: string
        - name: "senderEnterpriseNumber"
          in: query
          required: false
          description: filter on a sender organization
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "isAccepted"
          in: query
          required: false
          description: filter on suggestions already accepted by the client.
          schema:
            type: boolean
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RoutingRuleSuggestionsToAccept"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"

  /senderOrganizations/{senderEnterpriseNumber}/routingRulesSuggestions:
    post:
      tags:
        - "Sender routing rules suggestions"
      operationId: createRoutingRuleSuggestion
      description: "Suggestion to send to recipients to create a new partition routing rule to ease the receipt of this kind of messages. The recipient is free to accept the suggestion or not. You cannot create a routing rule suggestion with a condition that is already in another routing rule suggestion."
      summary: "Create a partition routing rule"
      parameters:
        - $ref: '#/components/parameters/EnterpriseNumberHeader'
        - name: "senderEnterpriseNumber"
          in: "path"
          required: true
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SenderRoutingRulesSuggestionToCreate"
      responses:
        201:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuggestionId"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:publicationmandate',
              'scope:document:management:consult:ws-eboxrestentreprise:publicationsender',
              'scope:document:management:ws-eboxrestentreprise:eboxrepresentativepublication']
      x-oauth2-required-scopes: any
    get:
      tags:
        - "Sender routing rules suggestions"
      operationId: getSenderRoutingRuleSuggestions
      description: "Get the routing rule suggestions sent to the recipients to create a new partition routing rule to ease the receipt of this kind of messages. This method does not show if the recipients accepted it or not."
      parameters:
        - $ref: '#/components/parameters/EnterpriseNumberHeader'
        - name: "senderEnterpriseNumber"
          in: "path"
          required: true
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SenderRoutingRulesSuggestionsResponse"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:publicationmandate',
              'scope:document:management:consult:ws-eboxrestentreprise:publicationsender',
              'scope:document:management:ws-eboxrestentreprise:eboxrepresentativepublication']

  /senderOrganizations/{senderEnterpriseNumber}/routingRulesSuggestions/{suggestionId}:
    delete:
      tags:
        - "Sender routing rules suggestions"
      summary: Remove a routing rule suggestion
      description: Remove a routing rule suggestion from the list of suggestions. The recipients who accepted it still have the routing rule configured for the ebox.
      operationId: deleteSenderRoutingRuleSuggestion
      parameters:
        - $ref: '#/components/parameters/EnterpriseNumberHeader'
        - name: "senderEnterpriseNumber"
          in: "path"
          required: true
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "suggestionId"
          in: "path"
          required: true
          schema:
            type: integer
      responses:
        204:
          description: "successful operation"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:publicationmandate',
              'scope:document:management:consult:ws-eboxrestentreprise:publicationsender',
              'scope:document:management:ws-eboxrestentreprise:eboxrepresentativepublication']

  /ebox/{enterpriseNumber}/partitions:
    get:
      tags:
        - "Partitions"
      summary: "Get partitions in the e-Box that the client has an admin right on them"
      description: ""
      operationId: "getPartitionsAdminRight"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          description: "Identifier issued by CBE for a registered organization. The CBE number in 10 digits format is used to identify the e-Box of en enterpise."
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
      responses:
        200:
          description: "successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Partitions"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseuser',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryuser',
              'scope:document:management:consult:ws-eboxrestentreprise:publicationweb']
      x-oauth2-required-scopes: any

    post:
      tags:
        - "Partitions"
      summary: "Create a new partition"
      description: "Create a new partition for the e-Box. The client must be one of the head of the company or configured as an e-Box administrator. Once created, the partition cannot be deleted. The partition creation must add the client as administrator of the new partition."
      operationId: "createPartition"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          description: "Identifier issued by CBE for a registered organization. The CBE number in 10 digits format is used to identify the e-Box of en enterpise."
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Partition"
      responses:
        204:
          description: "created"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        409:
          description: "The partition already exists"
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any

  /ebox/{enterpriseNumber}/partitions/{partitionId}:
    patch:
      tags:
        - "Partitions"
      summary: "Change the partition name"
      description: "Change the partition name. The client must be one of the head of the company or configured as an e-Box administrator."
      operationId: "patchPartition"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          description: "Identifier issued by CBE for a registered organization. The CBE number in 10 digits format is used to identify the e-Box of en enterpise."
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "partitionId"
          in: "path"
          description: "The partition identifier"
          required: true
          schema:
            type: "string"
      requestBody:
        required: true
        content:
          application/merge-patch+json:
            schema:
              $ref: "#/components/schemas/PartitionToPatch"
      responses:
        204:
          description: "successful operation"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
    delete:
      tags:
        - "Partitions"
      summary: "Delete a partition"
      description: "Delete a partition. The client must be one of the head of the company or an e-Box administrator. The client must ensure that all messages received in the partition are moved to another partition before delete. The client must also ensure that the senderPartition info is changed for all messages sent from the partition before delete. Both can be done by the operation /ebox/messages/changePartition in the MessageRegistry 3.x API. The client must also ensure there are no associated partition rules linked to this partition."
      operationId: "deletePartition"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          description: "Identifier issued by CBE for a registered organization. The CBE number in 10 digits format is used to identify the e-Box of en enterpise."
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "partitionId"
          in: "path"
          description: "The partition identifier"
          required: true
          schema:
            type: "string"
      responses:
        204:
          description: "successful operation"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
  /ebox/{enterpriseNumber}/partitions/{partitionId}/users:
    post:
      tags:
        - "Partition users"
      summary: "Add a user to a partition and set his consultation right."
      description: "Add rights to an user on a partition. The client must have an admin right on the partition."
      operationId: "createUserPartitionRight"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          description: "Identifier issued by CBE for a registered organization. The CBE number in 10 digits format is used to identify the e-Box of en enterpise."
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "partitionId"
          in: "path"
          description: "The partition identifier"
          required: true
          schema:
            type: "string"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UserPartitionRightToCreate"
      responses:
        204:
          description: "created"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        409:
          description: "userPartitionRights already exists on this user and this partition."
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
  /ebox/{enterpriseNumber}/partitions/{partitionId}/users/{ssin}:
    delete:
      tags:
        - "Partition users"
      summary: "Remove an user from a partition."
      description: "Remove an user from a partition. The client must have an admin right on the partition. If the request attempts to remove the unique admin of the partition, the request must be refused in order to keep at least one admin per partition."
      operationId: "deleteUserPartitionRights"
      parameters:
        - name: "enterpriseNumber"
          in: "path"
          required: true
          description: "Identifier issued by CBE for a registered organization. The CBE number in 10 digits format is used to identify the e-Box of en enterpise."
          schema:
            $ref: "#/components/schemas/EnterpriseNumber"
        - name: "partitionId"
          in: "path"
          description: "The partition identifier"
          required: true
          schema:
            type: "string"
            format: "[A-Za-z0-9\\-_.]{1,256}"
            example: "HRdepartment"
        - name: "ssin"
          in: "path"
          description: "The user identifier"
          required: true
          schema:
            type: "string"
            pattern: '^\d{11}$'
            example: "44022722580"
      responses:
        204:
          description: "successful operation"
        400:
          $ref: "#/components/responses/BadRequest"
        401:
          $ref: "#/components/responses/Unauthorized"
        403:
          $ref: "#/components/responses/Forbidden"
        404:
          $ref: "#/components/responses/NotFound"
        default:
          description: "error payload"
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      security:
        - Oauth:
            [
              'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin',
              'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible']
      x-oauth2-required-scopes: any
components:
  securitySchemes:
    Oauth:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: 'https://services-int.socialsecurity.be/REST/oauth/v5/authorize'
          tokenUrl: 'https://privateservices-int.socialsecurity.be/REST/oauth/v5/token'
          scopes:
            'scope:document:management:consult:ws-eboxrestentreprise:eboxresponsible': "This scope allows the RAE/co-RAE to consult their list of partitions and userPartitionRights."
            'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseadmin': "This scope allows the GL/co-GL under the qualities QUAL_COMPANY, QUAL_EMP_NOSS, QUAL_EMP_NOSSPLA to consult their list of partitions and userPartitionRights."
            'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryadmin': "This scope allows the GL/co-GL under the qualities  QUAL_SSC, QUAL_FSC, QUAL_SP_LEG to consult their list of partitions and userPartitionRights."
            'scope:document:management:consult:ws-eboxrestentreprise:eboxenterpriseuser': "This scope allows the user under the qualities QUAL_COMPANY, QUAL_EMP_NOSS, QUAL_EMP_NOSSPLA to consult their list of partitions."
            'scope:document:management:consult:ws-eboxrestentreprise:eboxmandataryuser': "This scope allows the user under the qualities QUAL_SSC, QUAL_FSC, QUAL_SP_LEG to consult their list of partitions."
            'scope:document:management:consult:ws-eboxrestentreprise:publicationweb': "This scope allows institutions to consult the list of partitions of e-Box Enterprise."
        clientCredentials:
          tokenUrl: 'https://privateservices-int.socialsecurity.be/REST/oauth/v5/token'
          scopes:
            'scope:document:management:consult:ws-eboxrestentreprise:publicationsender': "This scope allows Document sender to handle routing rule suggestions"
            'scope:document:management:consult:ws-eboxrestentreprise:publicationmandate': "This scope allows Document sender mandataries to handle routing rule suggestions"
            'scope:document:management:consult:ws-eboxrestentreprise:monitoring': "This scope is dedicated to monitoring tools"
            'scope:document:management:ws-eboxrestentreprise:eboxrepresentativepublication': "This scope allows mandated Document sender representative to handle routing rule suggestions on behalf of their clients"

  parameters:
    EnterpriseNumberHeader:
      name: On-Behalf-Of-Enterprise-Number
      in: header
      description: "If the client is a technical intermediary of another organization, this header must be used in order to identify for which organization the client is performing requests. A mandate must be signed in Mahis in order to accept the request."
      schema:
        type: string
        pattern: '^[0-1]\d{9}$'
        example: "0870288651"

  schemas:
    EnterpriseNumber:
      description: Identifier issued by CBE for a registered organization
      type: string
      pattern: '^[0-1]\d{9}$'
      example: "0406798006"

    HealthStatus:
      description: Response message for the API health
      type: object
      properties:
        status:
          description: "Level indicating the health status of the service: UP (functioning as expected), DOWN (suffering unexpected failures), DEGRADED (partly unavailable but service can be continued with reduced functionality), or a custom status value"
          type: string
      required:
        - status

    LocalizedString:
      description: Common type defined to provide a string value for each supported language among nl, fr, de
      type: object
      properties:
        nl:
          type: string
        fr:
          type: string
        de:
          type: string

    Partition:
      type: "object"
      description: "A partition is a sub-ebox that can receive and sand message through e-Box. A partition has its own identify and its own user access management."
      required:
        - "id"
      properties:
        id:
          $ref: "#/components/schemas/PartitionId"
        name:
          $ref: "#/components/schemas/LocalizedString"

    PartitionId:
      type: "string"
      description: "The partition business identifier. It will not be displayed to the end user but can be used as identifier in REST request."
      format: "[A-Za-z0-9\\-_.]{1,256}"
      example: "HRdepartment"

    Partitions:
      type: object
      properties:
        items:
          type: "array"
          items:
            $ref: "#/components/schemas/Partition"

    PartitionToPatch:
      type: "object"
      properties:
        name:
          $ref: "#/components/schemas/LocalizedString"

    Priority:
      type: "object"
      properties:
        priority:
          type: integer
          minimum: 0
          description: "The priority of the routing rule. The higher is this number, the less priority has the routing rule. Thus, among the rules that has a condition matching a message, the one with the lowest priority number must be applied to move the message to the target partition. If a new routing rule is created, all already existing routing rules with a priority number greater or equal to the new one must have their priority number incremented by 1."

    Problem:
      description: A Problem Details object (RFC 7807)
      type: object
      properties:
        type:
          type: string
          format: uri
          description: An absolute URI that identifies the problem type
        href:
          type: string
          format: uri
          description: An absolute URI that, when dereferenced, provides human-readable documentation for the problem type (e.g. using HTML).
        title:
          type: string
          description: A short summary of the problem type. Written in English and readable for engineers (usually not suited for non technical stakeholders and not localized).
          example: Service Unavailable
        status:
          type: integer
          format: int32
          description: The HTTP status code generated by the origin server for this occurrence of the problem.
          minimum: 400
          maximum: 600
          exclusiveMaximum: true
          example: 503
        detail:
          type: string
          description: A human-readable explanation specific to this occurrence of the problem
        instance:
          type: string
          format: uri
          description: An absolute URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
      example:
        {
          "type": "urn:problem-type:belgif:resourceNotFound",
          "href": "https://www.gcloud.belgium.be/rest/problems/resourceNotFound.html",
          "title": "Ebox not found",
          "status": 404,
          "detail": "The ebox specified as path parameter is not found.",
          "instance": "urn:uuid:123e4567-e89b-12d3-a456-426614174000",
          "environment": "acceptation" # additional properties specific to the problem type are allowed
        }

    RoutingRule:
      description: Partition rule to ease the receipt of this kind of messages
      type: object
      required:
        - conditions
        - targetPartitionId
      properties:
        conditions:
          $ref: "#/components/schemas/RoutingRuleConditions"
        targetPartitionId:
          $ref: "#/components/schemas/PartitionId"

    RoutingRuleConditions:
      description: "conditions to follow to map a message to a partition. Each condition is a triple of 3 optional properties (messageTypeId, senderApplicationId and senderEnterpriseNumber). If a property is not given or has a null value, it means that the property can have any value like a wildcard. For example, if condition:{senderApplicationId:myApplication, senderEnterpriseNumber:0123456789} then it means that every messages from the organization 0123456789 and the sender application myApplication should be moved to the target partition. Each condition are linked with an OR logical relation."
      type: array
      items:
        type: object
        properties:
          messageTypeId:
            type: string
            description: identification of the message type
          senderApplicationId:
            type: string
            description: identification of the sender application
          senderEnterpriseNumber:
            $ref: "#/components/schemas/EnterpriseNumber"

    RoutingRuleCreatedResponse:
      type: object
      description: Response to a successfull routing rule creation by the user
      required:
        - routingRuleId
      properties:
        routingRuleId:
          type: integer
          description: Routing rule identifier used as path parameter for operations on the routing rule

    RoutingRulesToConsult:
      type: object
      description: List of already created routing rules
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/RoutingRuleToConsult"

    RoutingRuleSuggestionsToAccept:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/RoutingRuleSuggestionToAccept"

    RoutingRuleSuggestionToAccept:
      allOf:
        - $ref: "#/components/schemas/SenderRoutingRulesSuggestion"
        - type: object
          properties:
            isAccepted:
              type: boolean
              description: "If true, the client already accepted and the suggested rule must be applied to the client's ebox if moveExistingMessages is true too.  If false, the client have not chosen yet if the rule must be applied."

    RoutingRuleToConsult:
      description: A routing rule with its identifier
      allOf:
        - type: object
          required:
            - routingRuleId
          properties:
            routingRuleId:
              type: integer
              description: Routing rule identifier used as path parameter for operations on the routing rule
            name:
              type: string
              description: Optional rule name given by the user
            creationDate:
              type: string
              description: Date when the user created the routing rule
              format: date-time
        - $ref: "#/components/schemas/Priority"
        - $ref: "#/components/schemas/SuggestionId" # In case the rule comes from a sender suggestion, this property is the suggestion identifier.
        - $ref: "#/components/schemas/RoutingRule"

    RoutingRuleToCreate:
      description: A routing rule and its optional name
      allOf:
        - type: object
          properties:
            name:
              type: string
              description: Optional rule name given by the user
            moveExistingMessages:
              type: boolean
              description: "If true, all messages in the ebox received before the creation of this rule must be moved to the target partition. If false, this rule applies only for messages received after the creation of this rule."
        - $ref: "#/components/schemas/Priority"
        - $ref: "#/components/schemas/SuggestionId" # In case the rule comes from a sender suggestion, this property is the suggestion identifier.
        - $ref: "#/components/schemas/RoutingRule"

    RoutingRuleToPatch:
      description: Object with properties from a RoutingRule that can be changed
      allOf:
        - type: object
          properties:
            name:
              type: string
              description: Optional rule name given by the user
        - $ref: "#/components/schemas/Priority"

    SenderRoutingRulesSuggestion:
      allOf:
        - $ref: "#/components/schemas/SuggestionId"
        - $ref: "#/components/schemas/SenderRoutingRulesSuggestionToCreate"

    SenderRoutingRulesSuggestionsResponse:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/SenderRoutingRulesSuggestion"

    SenderRoutingRulesSuggestionToCreate:
      description: Suggestion to send to the recipient to create a new partition routing rules to ease the receipt of this kind of messages. The description should not exceed 1000 characters.
      type: object
      required:
        - description
        - routingRuleConditions
      properties:
        description:
          $ref: "#/components/schemas/LocalizedString"
        routingRuleConditions:
          $ref: "#/components/schemas/RoutingRuleConditions"

    SuggestionId:
      type: object
      description: unique technical identifier of the suggestion
      properties:
        suggestionId:
          type: integer

    User:
      description: "A human user"
      type: "object"
      required:
        - "ssin"
      properties:
        ssin:
          description: Social Security Identification Number issued by the National Register or CBSS identifying the human user.
          type: string
          pattern: '^\d{11}$'
          example: "44022722580"

    UserPartitionRightToCreate:
      description: "Object definition for an admin to link an user to a partition and set its access rights on it."
      type: "object"
      required:
        - "user"
      properties:
        user:
          $ref: "#/components/schemas/User"


  responses:
    BadRequest:
      description: "The input message is incorrect."
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            badRequest:
              value:
                type: urn:problem-type:belgif:badRequest
                href: https://www.belgif.be/specification/rest/api-guide/problems/badRequest.html
                status: 400
                title: Bad Request
                detail: The input message is incorrect

    Unauthorized:
      description: "The consumer must pass a valid access token in the Authorization HTTP header for each request to a secure resource."
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            invalidAccessToken:
              value:
                type: urn:problem-type:belgif:invalidAccessToken
                href: https://www.belgif.be/specification/rest/api-guide/problems/invalidAccessToken.html
                status: 401
                title: Invalid Access Token
                detail: The Bearer access token found in the Authorization HTTP header is invalid

    Forbidden:
      description: "The consumer access token doesn’t have the required scope to invoke the operation or the user has not the required privilege."
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            missingScope:
              value:
                type: urn:problem-type:belgif:missingScope
                href: https://www.belgif.be/specification/rest/api-guide/problems/missingScope.html
                status: 403
                title: Missing Scope
                detail: Forbidden to access the resource
            missingPermission:
              value:
                type: urn:problem-type:belgif:missingPermission
                href: https://www.belgif.be/specification/rest/api-guide/problems/missingPermission.html
                status: 403
                title: Missing Permission
                detail: Not permitted to access the ressource

    NotFound:
      description: "The requested resource cannot be found."
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            eboxNotFound:
              value:
                type: urn:problem-type:belgif:resourceNotFound
                href: https://www.belgif.be/specification/rest/api-guide/problems/resourceNotFound.html
                status: 404
                title: ebox not found
                detail: "The ebox 0123456789 is not found"

    InternalServerError:
      description: "The server has encountered a situation it doesn’t know how to handle."
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            internalServerError:
              value:
                type: urn:problem-type:belgif:internalServerError
                href: https://www.belgif.be/specification/rest/api-guide/problems/internalServerError.html
                status: 500
                title: Internal Server Error

