{
  "openapi": "3.1.0",
  "info": {
    "title": "EDMRS API",
    "version": "2.1.0",
    "description": "EDMRS backend (SRS v2.1, Backend SRS v2.1). Success: { status, data }. Error: { error: { code, message, details? }, requestId }.\n\n**Signing in:** call `POST /api/v1/auth/login` with `{ \"email\", \"password\" }`. The server sets session cookies\n(`edmrs_access`, `edmrs_refresh`, `edmrs_csrf`) and the browser sends them with every later request.\nEvery write (POST/PUT/PATCH) also needs the header `X-CSRF-Token` set to the value of the `edmrs_csrf` cookie;\non this Swagger page it is filled in for you. Sign out with `POST /api/v1/auth/logout`."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "edmrs_access"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "requestId"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {}
            }
          },
          "requestId": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/auth/login": {
      "post": {
        "operationId": "postAuthLogin",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Sign in with email and password",
        "description": "Roles: Public (no session). SRS: FR-AU-001, FR-AU-006, FR-AU-007, FR-AU-010, NFR-SEC-002, NFR-SEC-006.",
        "x-roles": "public",
        "x-srs": [
          "FR-AU-001",
          "FR-AU-006",
          "FR-AU-007",
          "FR-AU-010",
          "NFR-SEC-002",
          "NFR-SEC-006"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Session started: { user, csrfToken, mustChangePassword } and the edmrs_access / edmrs_refresh / edmrs_csrf cookies. Two-factor accounts instead get { mfaRequired: true, challengeId, purpose, enrolment? } and no session."
          },
          "default": {
            "description": "Error envelope. INVALID_CREDENTIALS 401; TEMP_PASSWORD_EXPIRED 401; ACCOUNT_DISABLED 403; ACCOUNT_LOCKED 429",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "maxLength": 128
                  }
                },
                "required": [
                  "email",
                  "password"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/login/totp": {
      "post": {
        "operationId": "postAuthLoginTotp",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Second sign-in step: a TOTP code, or the first code of a required enrolment",
        "description": "Roles: Public (no session). SRS: FR-AU-007, NFR-SEC-007.",
        "x-roles": "public",
        "x-srs": [
          "FR-AU-007",
          "NFR-SEC-007"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ user, csrfToken, mustChangePassword } and the session cookies"
          },
          "default": {
            "description": "Error envelope. CHALLENGE_EXPIRED 401; INVALID_TOTP 401",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "challengeId": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^\\d{6}$"
                  }
                },
                "required": [
                  "challengeId",
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/totp": {
      "get": {
        "operationId": "getAuthTotp",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Two-factor status of the signed-in account",
        "description": "Roles: Any signed-in role. SRS: FR-AU-007. Allowed while a temporary password must be replaced.",
        "x-roles": "any",
        "x-srs": [
          "FR-AU-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ enabled, required, available }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/totp/setup": {
      "post": {
        "operationId": "postAuthTotpSetup",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Start TOTP enrolment: a new secret, its otpauth URI and QR code (SVG)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-AU-007.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-AU-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ challengeId, secret, otpauthUri, qrSvg }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/totp/confirm": {
      "post": {
        "operationId": "postAuthTotpConfirm",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Finish TOTP enrolment with a code from the authenticator app",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-AU-007.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-AU-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ enabled: true, required }"
          },
          "default": {
            "description": "Error envelope. CHALLENGE_EXPIRED 400; INVALID_TOTP 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "challengeId": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^\\d{6}$"
                  }
                },
                "required": [
                  "challengeId",
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/totp/disable": {
      "post": {
        "operationId": "postAuthTotpDisable",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Turn TOTP off with a current code (refused while it is required)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-AU-007.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-AU-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ enabled: false, required: false }"
          },
          "default": {
            "description": "Error envelope. TOTP_REQUIRED 409; TOTP_NOT_ENABLED 409; INVALID_TOTP 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "pattern": "^\\d{6}$"
                  }
                },
                "required": [
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/users/{id}/totp-requirement": {
      "patch": {
        "operationId": "patchUsersIdTotpRequirement",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Make TOTP required or optional for a Supreme or Super Admin account",
        "description": "Roles: Supreme Admin. SRS: FR-AU-007, NFR-SEC-007.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-AU-007",
          "NFR-SEC-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, totpRequired }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "required": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "required"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/me": {
      "get": {
        "operationId": "getAuthMe",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "The signed-in user",
        "description": "Roles: Any signed-in role. SRS: FR-AU-001, FR-AU-006. Allowed while a temporary password must be replaced.",
        "x-roles": "any",
        "x-srs": [
          "FR-AU-001",
          "FR-AU-006"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ id, name, email, mobile, role, status, mustChangePassword, totpEnabled, totpRequired, businessGroup, client, branch, timeZone, technicianKind, chain, engineerRevoked, createdAt }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/logout": {
      "post": {
        "operationId": "postAuthLogout",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Sign out and end the session",
        "description": "Roles: Any signed-in role. SRS: NFR-SEC-002. Allowed while a temporary password must be replaced.",
        "x-roles": "any",
        "x-srs": [
          "NFR-SEC-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ signedOut: true }; the session cookies are cleared"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/password-reset": {
      "post": {
        "operationId": "postAuthPasswordReset",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Request a password reset link (same answer whether or not the account exists)",
        "description": "Roles: Public (no session). SRS: FR-AU-008, NFR-SEC-006.",
        "x-roles": "public",
        "x-srs": [
          "FR-AU-008",
          "NFR-SEC-006"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ message }"
          },
          "default": {
            "description": "Error envelope. RATE_LIMITED 429",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  }
                },
                "required": [
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/password-reset/complete": {
      "post": {
        "operationId": "postAuthPasswordResetComplete",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Set a new password with a single-use, 30-minute reset token",
        "description": "Roles: Public (no session). SRS: FR-AU-008, FR-AU-009.",
        "x-roles": "public",
        "x-srs": [
          "FR-AU-008",
          "FR-AU-009"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ passwordChanged: true }; every session of the account ends"
          },
          "default": {
            "description": "Error envelope. RESET_TOKEN_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "password": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 128
                  }
                },
                "required": [
                  "token",
                  "password"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/register": {
      "post": {
        "operationId": "postAuthRegister",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Sign-up request for an individual owner or individual technician",
        "description": "Roles: Public (no session). SRS: FR-AU-002, FR-AU-004, BR-03.",
        "x-roles": "public",
        "x-srs": [
          "FR-AU-002",
          "FR-AU-004",
          "BR-03"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "201": {
            "description": "201 { id, status: \"PENDING\", emailConfirmed: false, businessGroup }; a confirmation link is emailed"
          },
          "default": {
            "description": "Error envelope. COUNTRY_NOT_OPEN 400; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "Owner",
                      "Technician"
                    ]
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  },
                  "countryCode": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 2,
                    "pattern": "^[A-Z]{2}$"
                  }
                },
                "required": [
                  "role",
                  "name",
                  "email",
                  "countryCode"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/register/confirm": {
      "post": {
        "operationId": "postAuthRegisterConfirm",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Confirm the sign-up email address with the emailed token (not in the v2.1 API table; required by FR-AU-003)",
        "description": "Roles: Public (no session). SRS: FR-AU-003.",
        "x-roles": "public",
        "x-srs": [
          "FR-AU-003"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ id, status: \"PENDING\", emailConfirmed: true }"
          },
          "default": {
            "description": "Error envelope. CONFIRMATION_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 128
                  }
                },
                "required": [
                  "token"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/signup-countries": {
      "get": {
        "operationId": "getSignupCountries",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Countries open for sign-up (an active region with an active Business Group)",
        "description": "Roles: Public (no session). SRS: FR-RG-002.",
        "x-roles": "public",
        "x-srs": [
          "FR-RG-002"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[{ countryCode, name }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/demo/outbox": {
      "get": {
        "operationId": "getDemoOutbox",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Demo deployments only (EDMRS_DEMO_OUTBOX=1): emails of the last 24 hours",
        "description": "Roles: Public (no session). SRS: SRS 2.4.",
        "x-roles": "public",
        "x-srs": [
          "SRS 2.4"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[{ id, to, subject, body, createdAt }]"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404 when the outbox is off",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/profile": {
      "patch": {
        "operationId": "patchProfile",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Update the caller's name and mobile",
        "description": "Roles: Any signed-in role. SRS: FR-US-005.",
        "x-roles": "any",
        "x-srs": [
          "FR-US-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "The signed-in user (as GET /auth/me)"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/profile/password": {
      "post": {
        "operationId": "postProfilePassword",
        "tags": [
          "Authentication and sign-up"
        ],
        "summary": "Change the password (also replaces a temporary password)",
        "description": "Roles: Any signed-in role. SRS: FR-US-005, FR-AU-006, FR-AU-009. Allowed while a temporary password must be replaced.",
        "x-roles": "any",
        "x-srs": [
          "FR-US-005",
          "FR-AU-006",
          "FR-AU-009"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ passwordChanged: true }; other sessions end, the current one is kept"
          },
          "default": {
            "description": "Error envelope. INVALID_PASSWORD 400; PASSWORD_REUSED 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "currentPassword": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "newPassword": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 128
                  }
                },
                "required": [
                  "currentPassword",
                  "newPassword"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/regions": {
      "get": {
        "operationId": "getRegions",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Regions with their status and settings",
        "description": "Roles: Supreme Admin. SRS: FR-RG-001.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-RG-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[{ id, countryCode, name, timeZone, dateFormat, numberFormat, supportEmail, supportPhone, status, businessGroupCount, createdAt }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postRegions",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Create a region with its settings (one per country)",
        "description": "Roles: Supreme Admin. SRS: FR-RG-001.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-RG-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 region"
          },
          "default": {
            "description": "Error envelope. REGION_EXISTS 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "countryCode": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 2,
                    "pattern": "^[A-Z]{2}$"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "dateFormat": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[DMY\\s/.,-]+$"
                  },
                  "numberFormat": {
                    "type": "string",
                    "maxLength": 16,
                    "pattern": "^[a-z]{2,3}(-[A-Z]{2})?$"
                  },
                  "supportEmail": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "supportPhone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "countryCode",
                  "name",
                  "timeZone"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/regions/{id}": {
      "patch": {
        "operationId": "patchRegionsId",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Update a region and its settings",
        "description": "Roles: Supreme Admin. SRS: FR-RG-001.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-RG-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "region"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; REGION_EXISTS 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "countryCode": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 2,
                    "pattern": "^[A-Z]{2}$"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "dateFormat": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[DMY\\s/.,-]+$"
                  },
                  "numberFormat": {
                    "type": "string",
                    "maxLength": 16,
                    "pattern": "^[a-z]{2,3}(-[A-Z]{2})?$"
                  },
                  "supportEmail": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "supportPhone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/regions/{id}/status": {
      "patch": {
        "operationId": "patchRegionsIdStatus",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Activate or deactivate a region (deactivation signs out and blocks every user beneath it)",
        "description": "Roles: Supreme Admin. SRS: FR-RG-001, FR-AU-012.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-RG-001",
          "FR-AU-012"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "region"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "ACTIVE",
                      "INACTIVE"
                    ]
                  }
                },
                "required": [
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/business-groups": {
      "get": {
        "operationId": "getBusinessGroups",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "All Business Groups with counts",
        "description": "Roles: Supreme Admin. SRS: FR-SA-001.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-SA-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[{ id, regionId, regionName, countryCode, name, contactName, email, phone, address, status, hasLogo, counts: { chains, individualOwners, superAdmins }, createdAt }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postBusinessGroups",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Create a Business Group",
        "description": "Roles: Supreme Admin. SRS: FR-SA-001, BR-01.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-SA-001",
          "BR-01"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 business group"
          },
          "default": {
            "description": "Error envelope. REGION_NOT_FOUND 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "regionId": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "name",
                  "regionId"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/business-groups/{id}": {
      "get": {
        "operationId": "getBusinessGroupsId",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "One Business Group (Super Admin: its own only)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-SA-001, FR-SA-003.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-SA-001",
          "FR-SA-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "business group"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchBusinessGroupsId",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Update a Business Group profile (Super Admin: its own only; regionId for Supreme Admin only)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-SA-001, FR-SA-003.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-SA-001",
          "FR-SA-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "business group"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; REGION_NOT_FOUND 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "regionId": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/business-groups/{id}/status": {
      "patch": {
        "operationId": "patchBusinessGroupsIdStatus",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Activate or deactivate a Business Group",
        "description": "Roles: Supreme Admin. SRS: FR-SA-001, FR-AU-012.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-SA-001",
          "FR-AU-012"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "business group"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "ACTIVE",
                      "INACTIVE"
                    ]
                  }
                },
                "required": [
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/business-groups/{id}/logo": {
      "get": {
        "operationId": "getBusinessGroupsIdLogo",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "The group logo image",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-SA-003.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-SA-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "image/png or image/jpeg body"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; LOGO_NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "putBusinessGroupsIdLogo",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Upload the group logo (raw PNG or JPEG body, at most 512 KB and 1000 x 1000 px)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-SA-003, NFR-PRIV-001.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-SA-003",
          "NFR-PRIV-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ type, width, height, bytes }"
          },
          "default": {
            "description": "Error envelope. UNSUPPORTED_MEDIA_TYPE 415; LOGO_TOO_LARGE 413; LOGO_INVALID 400; LOGO_DIMENSIONS 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    },
    "/api/v1/points-per-device": {
      "get": {
        "operationId": "getPointsPerDevice",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Points posted to both ledgers per future registration",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-SA-004.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-SA-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ pointsPerDevice, updatedAt }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "putPointsPerDevice",
        "tags": [
          "Regions, Business Groups and settings"
        ],
        "summary": "Set points per future registration (0 to 100,000; audit-logged)",
        "description": "Roles: Supreme Admin. SRS: FR-SA-004.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-SA-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ pointsPerDevice, updatedAt }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pointsPerDevice": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100000
                  }
                },
                "required": [
                  "pointsPerDevice"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/clients": {
      "get": {
        "operationId": "getClients",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Clients in the caller's scope (Super Admin: its group; Chain Admin and Owner: their own)",
        "description": "Roles: Super Admin, Chain Admin, Owner. SRS: FR-SU-002.",
        "x-roles": [
          "Super Admin",
          "Chain Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-SU-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "CHAIN",
                "INDIVIDUAL"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACTIVE",
                "INACTIVE"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [client], total, page, pageSize }; client = { id, businessGroupId, type, name, registrationNumber, contactName, email, phone, address, timeZone, status, deactivatedAt, hasLogo, branchCount, deviceCount, createdAt }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postClients",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Create a chain (with its first Chain Admin) or an individual owner (with one branch and one Owner account)",
        "description": "Roles: Super Admin. SRS: FR-SU-001, FR-AU-005, BR-02.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-SU-001",
          "FR-AU-005",
          "BR-02"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { client, branchId, account: { id, role, email, temporaryPassword } } - the temporary password is shown only in this response"
          },
          "default": {
            "description": "Error envelope. EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "CHAIN",
                      "INDIVIDUAL"
                    ]
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "registrationNumber": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "May be empty"
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "chainAdmin": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 150
                      },
                      "email": {
                        "type": "string",
                        "maxLength": 190,
                        "format": "email"
                      },
                      "mobile": {
                        "type": "string",
                        "maxLength": 32,
                        "pattern": "^[0-9+()\\-\\s]*$",
                        "description": "May be empty"
                      }
                    },
                    "required": [
                      "name",
                      "email"
                    ],
                    "additionalProperties": false,
                    "description": "Required when type matches (see endpoint docs)"
                  },
                  "owner": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 150
                      },
                      "email": {
                        "type": "string",
                        "maxLength": 190,
                        "format": "email"
                      },
                      "mobile": {
                        "type": "string",
                        "maxLength": 32,
                        "pattern": "^[0-9+()\\-\\s]*$",
                        "description": "May be empty"
                      }
                    },
                    "required": [
                      "name",
                      "email"
                    ],
                    "additionalProperties": false,
                    "description": "Required when type matches (see endpoint docs)"
                  },
                  "branch": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "maxLength": 150,
                        "description": "May be empty"
                      },
                      "address": {
                        "type": "string",
                        "maxLength": 255,
                        "description": "May be empty"
                      },
                      "city": {
                        "type": "string",
                        "maxLength": 100,
                        "description": "May be empty"
                      }
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type",
                  "name"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/clients/{id}": {
      "patch": {
        "operationId": "patchClientsId",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Update a client (own group only)",
        "description": "Roles: Super Admin. SRS: FR-SU-002.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-SU-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "client"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "registrationNumber": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "May be empty"
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/clients/{id}/status": {
      "patch": {
        "operationId": "patchClientsIdStatus",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Deactivate or reactivate a client (its users are signed out and blocked; data is kept)",
        "description": "Roles: Super Admin. SRS: FR-SU-002, FR-AU-012.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-SU-002",
          "FR-AU-012"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "client"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "ACTIVE",
                      "INACTIVE"
                    ]
                  }
                },
                "required": [
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/clients/{id}/logo": {
      "get": {
        "operationId": "getClientsIdLogo",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "A chain client's logo image",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin, Owner, Technician. SRS: FR-CH-001.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-CH-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "image/png or image/jpeg body"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; LOGO_NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "putClientsIdLogo",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Upload a chain client's logo (raw PNG or JPEG body, at most 512 KB and 1000 x 1000 px)",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin. SRS: FR-CH-001, NFR-PRIV-001.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-001",
          "NFR-PRIV-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ type, width, height, bytes }"
          },
          "default": {
            "description": "Error envelope. NOT_A_CHAIN 400; UNSUPPORTED_MEDIA_TYPE 415; LOGO_TOO_LARGE 413; LOGO_INVALID 400; LOGO_DIMENSIONS 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-profile": {
      "get": {
        "operationId": "getChainProfile",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "The Chain Admin's own chain profile",
        "description": "Roles: Chain Admin. SRS: FR-CH-001.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "client"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchChainProfile",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Update the chain profile",
        "description": "Roles: Chain Admin. SRS: FR-CH-001.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "client"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "registrationNumber": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "May be empty"
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email",
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-summary": {
      "get": {
        "operationId": "getChainSummary",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Devices by branch and product; devices serviced in the last 30 and 90 days",
        "description": "Roles: Chain Admin. SRS: FR-DB-003.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-DB-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ devicesByBranch: [{ branchId, name, code, status, devices, activeDevices }], devicesByProduct: [{ product, devices }], servicedLast30Days, servicedLast90Days }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/branches": {
      "get": {
        "operationId": "getBranches",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Branches in the caller's scope (Super Admin: names only)",
        "description": "Roles: Super Admin, Chain Admin, Branch Admin. SRS: FR-CH-002.",
        "x-roles": [
          "Super Admin",
          "Chain Admin",
          "Branch Admin"
        ],
        "x-srs": [
          "FR-CH-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACTIVE",
                "INACTIVE",
                "MERGED",
                "DELETED"
              ]
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "[branch]; branch = { id, clientId, name, code, address, city, contactName, phone, timeZone, status, mergedInto, deviceCount, branchAdminCount, createdAt } (Super Admin: { id, clientId, clientName, name, status })"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postBranches",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Create a branch, optionally with its first Branch Admin",
        "description": "Roles: Chain Admin. SRS: FR-CH-002, FR-CH-003, FR-AU-005.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-002",
          "FR-CH-003",
          "FR-AU-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { branch, account: { id, role, email, temporaryPassword } | null }"
          },
          "default": {
            "description": "Error envelope. BRANCH_CODE_IN_USE 409; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "code": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[A-Za-z0-9_-]+$"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "city": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "branchAdmin": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 150
                      },
                      "email": {
                        "type": "string",
                        "maxLength": 190,
                        "format": "email"
                      },
                      "mobile": {
                        "type": "string",
                        "maxLength": 32,
                        "pattern": "^[0-9+()\\-\\s]*$",
                        "description": "May be empty"
                      }
                    },
                    "required": [
                      "name",
                      "email"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "name",
                  "code"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/branches/{id}": {
      "patch": {
        "operationId": "patchBranchesId",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Update a branch (status ACTIVE or INACTIVE)",
        "description": "Roles: Chain Admin. SRS: FR-CH-002.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "branch"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BRANCH_CODE_IN_USE 409; BRANCH_CLOSED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "code": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[A-Za-z0-9_-]+$"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "May be empty"
                  },
                  "city": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "contactName": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "May be empty"
                  },
                  "timeZone": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "ACTIVE",
                      "INACTIVE"
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/branches/{id}/delete": {
      "post": {
        "operationId": "postBranchesIdDelete",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Soft-delete a branch (refused while it has active devices)",
        "description": "Roles: Chain Admin. SRS: FR-CH-002, BR-16.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-002",
          "BR-16"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "branch (status DELETED)"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BRANCH_HAS_ACTIVE_DEVICES 409; BRANCH_CLOSED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/branches/merge-impact": {
      "get": {
        "operationId": "getBranchesMergeImpact",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "What a merge would move: devices, issues and Branch Admins",
        "description": "Roles: Chain Admin. SRS: FR-CH-004.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "sourceIds",
            "in": "query",
            "required": true,
            "schema": {
              "anyOf": [
                {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "minItems": 1,
                  "maxItems": 20
                },
                {
                  "type": "string",
                  "format": "uuid"
                }
              ]
            }
          },
          {
            "name": "targetId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ target, sources, moves: { devices, issues, openIssues, branchAdmins, technicians } }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BRANCH_NOT_ACTIVE 409; MERGE_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/branches/merge": {
      "post": {
        "operationId": "postBranchesMerge",
        "tags": [
          "Clients, chains and branches"
        ],
        "summary": "Merge branches in one transaction (devices with their QR tokens, service records and issues, Branch Admins and branch technicians move to the target)",
        "description": "Roles: Chain Admin. SRS: FR-CH-005, BR-16, NFR-REL-001.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-CH-005",
          "BR-16",
          "NFR-REL-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ target, merged: [sourceId], moved: { devices, issues, openIssues, branchAdmins, technicians } }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BRANCH_NOT_ACTIVE 409; MERGE_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sourceIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "maxItems": 20
                  },
                  "targetId": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "sourceIds",
                  "targetId"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/registration-requests": {
      "get": {
        "operationId": "getRegistrationRequests",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Sign-up requests waiting for the Business Group (confirmed email, not expired)",
        "description": "Roles: Super Admin. SRS: FR-AU-003, FR-AU-004.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-AU-003",
          "FR-AU-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "PENDING",
                "APPROVED",
                "REJECTED",
                "EXPIRED"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "[{ id, role, name, email, mobile, countryCode, businessGroupId, emailConfirmed, status, decisionReason, reviewedAt, expiresAt, createdAt }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/registration-requests/{id}/decision": {
      "post": {
        "operationId": "postRegistrationRequestsIdDecision",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Approve (creates the account, emails a temporary password) or reject (reason required, emailed)",
        "description": "Roles: Super Admin. SRS: FR-AU-003, FR-AU-005, BR-02.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-AU-003",
          "FR-AU-005",
          "BR-02"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ request, account: { id, role, email, temporaryPassword } | null }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; REQUEST_CLOSED 409; EMAIL_NOT_CONFIRMED 409; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "APPROVE",
                      "REJECT"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500,
                    "description": "Required when decision matches (see endpoint docs)"
                  }
                },
                "required": [
                  "decision"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/users": {
      "get": {
        "operationId": "getUsers",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Accounts the caller manages, optionally of one role, technician kind or chain",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin. SRS: FR-SA-001, FR-SU-003, FR-US-004.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-SA-001",
          "FR-SU-003",
          "FR-US-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "role",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "Supreme Admin",
                "Super Admin",
                "Chain Admin",
                "Branch Admin",
                "Chain Engineer",
                "Owner",
                "Technician"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACTIVE",
                "INACTIVE"
              ]
            }
          },
          {
            "name": "technicianKind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "INDIVIDUAL",
                "CHAIN",
                "CHAIN_BRANCH"
              ]
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [user], total, page, pageSize }; user = { id, name, email, mobile, role, status, businessGroupId, clientId, clientName, branchId, branchName, technicianKind, linkedChain, totpEnabled, totpRequired, mustChangePassword, engineerRevokedAt, createdAt }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/admin-accounts": {
      "post": {
        "operationId": "postAdminAccounts",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Create a Super Admin (of one Business Group) or a Supreme Admin",
        "description": "Roles: Supreme Admin. SRS: FR-SA-001, FR-AU-005.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-SA-001",
          "FR-AU-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, role, email, temporaryPassword } - the temporary password is shown only in this response and emailed"
          },
          "default": {
            "description": "Error envelope. BUSINESS_GROUP_NOT_FOUND 400; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "Super Admin",
                      "Supreme Admin"
                    ]
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  },
                  "businessGroupId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Required when role matches (see endpoint docs)"
                  }
                },
                "required": [
                  "role",
                  "name",
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-admins": {
      "post": {
        "operationId": "postChainAdmins",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Add a Chain Admin to a chain of the group",
        "description": "Roles: Super Admin. SRS: FR-SU-002, FR-AU-005.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-SU-002",
          "FR-AU-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, role, email, temporaryPassword } - the temporary password is shown only in this response and emailed"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "clientId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  }
                },
                "required": [
                  "clientId",
                  "name",
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/branch-admins": {
      "post": {
        "operationId": "postBranchAdmins",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Create a Branch Admin for one active branch of the chain",
        "description": "Roles: Chain Admin. SRS: FR-US-001, FR-AU-005.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-001",
          "FR-AU-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, role, email, temporaryPassword } - the temporary password is shown only in this response and emailed"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BRANCH_NOT_ACTIVE 409; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "branchId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  }
                },
                "required": [
                  "branchId",
                  "name",
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/technicians": {
      "post": {
        "operationId": "postTechnicians",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Create a chain technician (with branchId: serves that branch; without: every branch of the chain)",
        "description": "Roles: Chain Admin. SRS: FR-US-002, FR-AU-005.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-002",
          "FR-AU-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, role, email, temporaryPassword } - the temporary password is shown only in this response and emailed"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BRANCH_NOT_ACTIVE 409; EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "branchId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  }
                },
                "required": [
                  "name",
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-technicians/link": {
      "post": {
        "operationId": "postChainTechniciansLink",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Add an individual technician of the same group to the chain by email",
        "description": "Roles: Chain Admin. SRS: FR-US-003, BR-15.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-003",
          "BR-15"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { linkId, technician }"
          },
          "default": {
            "description": "Error envelope. TECHNICIAN_NOT_FOUND 404; TECHNICIAN_NOT_ACTIVE 409; TECHNICIAN_ALREADY_LINKED 409; TECHNICIAN_IN_OTHER_CHAIN 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  }
                },
                "required": [
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-technicians/{id}/remove": {
      "post": {
        "operationId": "postChainTechniciansIdRemove",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Remove an added individual technician (id = technician user id) from the chain; the account stays active",
        "description": "Roles: Chain Admin. SRS: FR-US-003.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ removed: true, technicianId }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-engineers": {
      "get": {
        "operationId": "getChainEngineers",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "The chain's Chain Engineers, active and removed",
        "description": "Roles: Chain Admin. SRS: FR-US-002.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[user]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postChainEngineers",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Create a Chain Engineer (read-only access to the chain's issues)",
        "description": "Roles: Chain Admin. SRS: FR-US-002, FR-AU-005.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-002",
          "FR-AU-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, role, email, temporaryPassword } - the temporary password is shown only in this response and emailed"
          },
          "default": {
            "description": "Error envelope. EMAIL_IN_USE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 190,
                    "format": "email"
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  }
                },
                "required": [
                  "name",
                  "email"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/chain-engineers/{id}/remove": {
      "post": {
        "operationId": "postChainEngineersIdRemove",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Remove a Chain Engineer; its access to current issues ends at once, solved issues stay readable",
        "description": "Roles: Chain Admin. SRS: FR-US-002.",
        "x-roles": [
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "user"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; ALREADY_REMOVED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/users/{id}": {
      "patch": {
        "operationId": "patchUsersId",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Update name and mobile; move a Branch Admin to another branch (Chain Admin)",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin. SRS: FR-US-001, FR-US-004, FR-SU-003.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-US-001",
          "FR-US-004",
          "FR-SU-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "user"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; MOVE_NOT_ALLOWED 403; BRANCH_NOT_ACTIVE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "mobile": {
                    "type": "string",
                    "maxLength": 32,
                    "pattern": "^[0-9+()\\-\\s]*$",
                    "description": "May be empty"
                  },
                  "branchId": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/users/{id}/status": {
      "patch": {
        "operationId": "patchUsersIdStatus",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Activate or deactivate an account (never your own; never the last active Supreme Admin)",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin. SRS: FR-SA-002, FR-US-004, FR-AU-012.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-SA-002",
          "FR-US-004",
          "FR-AU-012"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "user"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; OWN_STATUS 403; LAST_SUPREME_ADMIN 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "ACTIVE",
                      "INACTIVE"
                    ]
                  }
                },
                "required": [
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/users/{id}/force-password-reset": {
      "post": {
        "operationId": "postUsersIdForcePasswordReset",
        "tags": [
          "Accounts and profile"
        ],
        "summary": "Issue a new temporary password; all the account's sessions end",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin. SRS: FR-AU-011, FR-SU-003, FR-US-004.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-AU-011",
          "FR-SU-003",
          "FR-US-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, temporaryPassword }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; OWN_ACCOUNT 403",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/catalog": {
      "get": {
        "operationId": "getCatalog",
        "tags": [
          "Catalog"
        ],
        "summary": "Products and parts of the caller's catalog (readers see active items only)",
        "description": "Roles: Super Admin, Chain Admin, Branch Admin, Owner, Technician. SRS: FR-AD-001, FR-AD-002.",
        "x-roles": [
          "Super Admin",
          "Chain Admin",
          "Branch Admin",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-AD-001",
          "FR-AD-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "PRODUCT",
                "PART"
              ]
            }
          },
          {
            "name": "active",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "[{ id, kind, name, category, brand, model, partCode, notes, active, catalog: \"CHAIN\" | \"BUSINESS_GROUP\", fits?: [{ id, name }], createdAt }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postCatalog",
        "tags": [
          "Catalog"
        ],
        "summary": "Create a product or part (Super Admin: group catalog; Chain Admin: chain catalog)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-AD-001, FR-AD-002.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-AD-001",
          "FR-AD-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, kind, name, category, brand, model, partCode, notes, active, catalog: \"CHAIN\" | \"BUSINESS_GROUP\", fits?: [{ id, name }], createdAt }"
          },
          "default": {
            "description": "Error envelope. FITS_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "PRODUCT",
                      "PART"
                    ]
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "category": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "model": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "partCode": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "May be empty"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "May be empty"
                  },
                  "fits": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "maxItems": 200
                  }
                },
                "required": [
                  "kind",
                  "name"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/catalog/{id}": {
      "patch": {
        "operationId": "patchCatalogId",
        "tags": [
          "Catalog"
        ],
        "summary": "Update a product or part",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-AD-001, FR-AD-002.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-AD-001",
          "FR-AD-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, kind, name, category, brand, model, partCode, notes, active, catalog: \"CHAIN\" | \"BUSINESS_GROUP\", fits?: [{ id, name }], createdAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; FITS_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "category": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "model": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "partCode": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "May be empty"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "May be empty"
                  },
                  "fits": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "maxItems": 200
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/catalog/{id}/status": {
      "patch": {
        "operationId": "patchCatalogIdStatus",
        "tags": [
          "Catalog"
        ],
        "summary": "Deactivate or reactivate a catalog item (items are never deleted)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-AD-003.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-AD-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, kind, name, category, brand, model, partCode, notes, active, catalog: \"CHAIN\" | \"BUSINESS_GROUP\", fits?: [{ id, name }], createdAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "active"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/devices": {
      "get": {
        "operationId": "getDevices",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Devices in scope, paged, filtered and sorted (retired hidden unless view=retired|all); print=1 for a statement",
        "description": "Roles: Chain Admin, Branch Admin, Owner, Technician. SRS: FR-DV-005, FR-DV-006, UI-030-1, BR-11.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-DV-005",
          "FR-DV-006",
          "UI-030-1",
          "BR-11"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "view",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "retired",
                "all"
              ]
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "productId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "product",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 150
            }
          },
          {
            "name": "brand",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "stickerStatus",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "NOT_PRINTED",
                "PRINTED",
                "DELIVERED",
                "REPRINT_REQUESTED"
              ]
            }
          },
          {
            "name": "registeredFrom",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "registeredTo",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "lastServiceFrom",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "lastServiceTo",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [{ id, deviceCode, label, productId, productLabel, brand, model, serialNumber, location, purchaseDate, notes, status, stickerStatus, branch: { id, name, code }, client: { id, name, type }, timeZone, registeredBy, createdAt, lastServiceAt }], total, page, pageSize } | print=1: { items (max 2000), total, truncated, statement: { reference, printedAt, printedBy, filters, title, summary } }"
          },
          "default": {
            "description": "Error envelope. VALIDATION_ERROR 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postDevices",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Register a device: Device Code, QR token, sticker status and both accruals in one transaction",
        "description": "Roles: Branch Admin, Owner. SRS: FR-DV-001, FR-DV-002, FR-DV-003, FR-PL-002, NFR-REL-001.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-DV-001",
          "FR-DV-002",
          "FR-DV-003",
          "FR-PL-002",
          "NFR-REL-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, deviceCode, label, productId, productLabel, brand, model, serialNumber, location, purchaseDate, notes, status, stickerStatus, branch: { id, name, code }, client: { id, name, type }, timeZone, registeredBy, createdAt, lastServiceAt } + { serviceRecords: [], openIssues, pendingReprintRequest, qrCodeAvailable }"
          },
          "default": {
            "description": "Error envelope. PRODUCT_REQUIRED 400; PRODUCT_INVALID 400; DUPLICATE_SERIAL 409 (details.existing); BRANCH_NOT_ACTIVE 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "productId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "productName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "model": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "serialNumber": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "location": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "purchaseDate": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                    "description": "May be empty"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "May be empty"
                  },
                  "confirmDuplicateSerial": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "label"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/devices/export": {
      "get": {
        "operationId": "getDevicesExport",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "The filtered device list as CSV (same filters and sort as GET /devices)",
        "description": "Roles: Chain Admin, Branch Admin, Owner. SRS: FR-DV-009.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-DV-009"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "view",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "retired",
                "all"
              ]
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "productId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "product",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 150
            }
          },
          {
            "name": "brand",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "stickerStatus",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "NOT_PRINTED",
                "PRINTED",
                "DELIVERED",
                "REPRINT_REQUESTED"
              ]
            }
          },
          {
            "name": "registeredFrom",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "registeredTo",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "lastServiceFrom",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "lastServiceTo",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv file"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/devices/{id}": {
      "get": {
        "operationId": "getDevicesId",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Device details and its three newest service records",
        "description": "Roles: Chain Admin, Branch Admin, Owner, Technician. SRS: FR-DV-007, FR-TE-002.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-DV-007",
          "FR-TE-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, deviceCode, label, productId, productLabel, brand, model, serialNumber, location, purchaseDate, notes, status, stickerStatus, branch: { id, name, code }, client: { id, name, type }, timeZone, registeredBy, createdAt, lastServiceAt } + { serviceRecords: [{ id, deviceId, description, technician: { id, name }, createdAt }] (max 3, newest first), openIssues, pendingReprintRequest, qrCodeAvailable }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchDevicesId",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Update device details (never the Device Code or QR token)",
        "description": "Roles: Branch Admin, Owner. SRS: FR-DV-004, BR-05.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-DV-004",
          "BR-05"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "device (as GET /devices/{id})"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; DUPLICATE_SERIAL 409; PRODUCT_INVALID 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "productId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "productName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "model": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "serialNumber": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  },
                  "location": {
                    "type": "string",
                    "maxLength": 150,
                    "description": "May be empty"
                  },
                  "purchaseDate": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                    "description": "May be empty"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "May be empty"
                  },
                  "confirmDuplicateSerial": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/devices/{id}/qr": {
      "get": {
        "operationId": "getDevicesIdQr",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "The device's current QR code as SVG, for its own Owner only; each view audited",
        "description": "Roles: Owner. SRS: FR-DV-008, BR-13, FR-AL-001.",
        "x-roles": [
          "Owner"
        ],
        "x-srs": [
          "FR-DV-008",
          "BR-13",
          "FR-AL-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "image/svg+xml body (Content-Disposition: inline)"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; QR_NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/devices/{id}/retire": {
      "post": {
        "operationId": "postDevicesIdRetire",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Retire a device (no points change)",
        "description": "Roles: Branch Admin, Owner. SRS: FR-DV-005, BR-06, BR-10.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-DV-005",
          "BR-06",
          "BR-10"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "device"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; STATUS_UNCHANGED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/devices/{id}/reactivate": {
      "post": {
        "operationId": "postDevicesIdReactivate",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Reactivate a retired device (no points change)",
        "description": "Roles: Branch Admin, Owner. SRS: FR-DV-005, BR-06.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-DV-005",
          "BR-06"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "device"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; STATUS_UNCHANGED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/qr/resolve": {
      "post": {
        "operationId": "postQrResolve",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Resolve a scanned token or typed Device Code to the device and its three newest records",
        "description": "Roles: Technician. SRS: FR-QR-002, FR-TE-001, FR-TE-002, BR-04, BR-17.",
        "x-roles": [
          "Technician"
        ],
        "x-srs": [
          "FR-QR-002",
          "FR-TE-001",
          "FR-TE-002",
          "BR-04",
          "BR-17"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, deviceCode, label, productId, productLabel, brand, model, serialNumber, location, purchaseDate, notes, status, stickerStatus, branch: { id, name, code }, client: { id, name, type }, timeZone, registeredBy, createdAt, lastServiceAt } + { acceptsServiceRecords, serviceRecords, openIssues: [{ id, code, title, status, createdAt }] }"
          },
          "default": {
            "description": "Error envelope. DEVICE_NOT_FOUND 404 (unknown, revoked and out-of-scope alike); RATE_LIMITED 429",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{16,64}$"
                  },
                  "deviceCode": {
                    "type": "string",
                    "maxLength": 24
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/devices/{id}/service-records": {
      "post": {
        "operationId": "postDevicesIdServiceRecords",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Add a service record (10 to 2,000 characters), idempotent by submission key (body submissionKey or Idempotency-Key header)",
        "description": "Roles: Technician. SRS: FR-TE-003, FR-SR-001, BR-07, BR-10.",
        "x-roles": [
          "Technician"
        ],
        "x-srs": [
          "FR-TE-003",
          "FR-SR-001",
          "BR-07",
          "BR-10"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { replay: false, record, serviceRecords (max 3) } | 200 { replay: true, ... } for a repeated key"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; DEVICE_RETIRED 409; IDEMPOTENCY_KEY_REUSED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "description": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 2000
                  },
                  "submissionKey": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{8,100}$"
                  }
                },
                "required": [
                  "description"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/service-records": {
      "get": {
        "operationId": "getServiceRecords",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "Service history of every device in scope; print=1 for a statement grouped by branch",
        "description": "Roles: Chain Admin, Branch Admin, Owner. SRS: FR-SR-002, UI-030-1, UI-030-5.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-SR-002",
          "UI-030-1",
          "UI-030-5"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [{ id, description, createdAt, technician, device: { id, deviceCode, label }, branch, timeZone }], total, page, pageSize } | print=1: { items, total, truncated, statement: { ..., groups: [{ branch, records (count) }] } } (items ordered by branch)"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/service-records/export": {
      "get": {
        "operationId": "getServiceRecordsExport",
        "tags": [
          "Devices, QR and service records"
        ],
        "summary": "The filtered service history as CSV",
        "description": "Roles: Chain Admin, Branch Admin, Owner. SRS: FR-SR-002.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-SR-002"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv file"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/stickers": {
      "get": {
        "operationId": "getStickers",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Sticker queue: chain devices for the Chain Admin, individual owners' devices for the Super Admin, own branch for a Branch Admin or Owner (at most 500)",
        "description": "Roles: Super Admin, Chain Admin, Branch Admin, Owner. SRS: FR-QR-003, FR-QR-004, BR-12.",
        "x-roles": [
          "Super Admin",
          "Chain Admin",
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-QR-003",
          "FR-QR-004",
          "BR-12"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "stickerStatus",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "NOT_PRINTED",
                "PRINTED",
                "DELIVERED",
                "REPRINT_REQUESTED"
              ]
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "registeredFrom",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "registeredTo",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [{ id, deviceCode, label, productLabel, stickerStatus, createdAt, branch, client }], total, truncated, countsByStatus, canPrint }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/sticker-layouts": {
      "get": {
        "operationId": "getStickerLayouts",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Selectable layouts from the sticker layout file (EDMRS_STICKER_LAYOUTS, default src/config/sticker-layouts.json)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-005.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-005"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[{ id, name, page, columns, rows, perSheet }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/sticker-jobs": {
      "post": {
        "operationId": "postStickerJobs",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Generate a sheet PDF for 1 to 500 devices the caller prints for (one device outside scope refuses the job)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-005, FR-QR-006, FR-QR-007, BR-12.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-005",
          "FR-QR-006",
          "FR-QR-007",
          "BR-12"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, layoutId, deviceCount, status: GENERATED|PRINTED|DELIVERED, deliveryDate, recipientNote, createdAt, printedAt, deliveredAt, downloadPath }"
          },
          "default": {
            "description": "Error envelope. DEVICES_NOT_FOUND 404; DEVICE_RETIRED 409; LAYOUT_NOT_FOUND 400",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deviceIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "maxItems": 500
                  },
                  "layoutId": {
                    "type": "string",
                    "maxLength": 32
                  }
                },
                "required": [
                  "deviceIds"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/sticker-jobs/{id}/download": {
      "get": {
        "operationId": "getStickerJobsIdDownload",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Download a sheet (only the printer responsible for all its devices)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-007.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "application/pdf file"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/sticker-jobs/{id}/printed": {
      "post": {
        "operationId": "postStickerJobsIdPrinted",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Confirm a sheet printed (skips devices reissued since)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-008.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-008"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ job: { id, layoutId, deviceCount, status: GENERATED|PRINTED|DELIVERED, deliveryDate, recipientNote, createdAt, printedAt, deliveredAt, downloadPath }, printed, skippedReissued, skippedPendingReprint }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; JOB_ALREADY_PRINTED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/sticker-jobs/{id}/delivered": {
      "post": {
        "operationId": "postStickerJobsIdDelivered",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Record a printed sheet delivered (only devices still PRINTED become DELIVERED)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-009.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-009"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ job: { id, layoutId, deviceCount, status: GENERATED|PRINTED|DELIVERED, deliveryDate, recipientNote, createdAt, printedAt, deliveredAt, downloadPath }, delivered }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; JOB_NOT_PRINTED 409; JOB_ALREADY_DELIVERED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deliveryDate": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "recipientNote": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "deliveryDate"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/stickers/delivered": {
      "post": {
        "operationId": "postStickersDelivered",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Record printed stickers delivered, one or many",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-009.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-009"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ delivered, deliveryDate, recipientNote }"
          },
          "default": {
            "description": "Error envelope. DEVICES_NOT_FOUND 404; STICKER_NOT_PRINTED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deviceIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "maxItems": 500
                  },
                  "deliveryDate": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "recipientNote": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "deviceIds",
                  "deliveryDate"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/reprint-requests": {
      "get": {
        "operationId": "getReprintRequests",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Reprint requests for devices the caller prints for (default PENDING)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-011.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-011"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "PENDING",
                "APPROVED",
                "REJECTED",
                "ALL"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "[{ id, status, reason, decisionReason, originalStickerStatus, device: { id, deviceCode, label, stickerStatus }, branch, client, requestedBy, reviewedBy, createdAt, decidedAt }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postReprintRequests",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Request a reprint with a reason (one pending request per device)",
        "description": "Roles: Branch Admin, Owner. SRS: FR-QR-010, FR-NT-001.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-QR-010",
          "FR-NT-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, status, reason, decisionReason, originalStickerStatus, device: { id, deviceCode, label, stickerStatus }, branch, client, requestedBy, reviewedBy, createdAt, decidedAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; DEVICE_RETIRED 409; REPRINT_ALREADY_PENDING 409; STICKER_NOT_PRINTED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deviceId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 500
                  }
                },
                "required": [
                  "deviceId",
                  "reason"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/reprint-requests/{id}/decision": {
      "post": {
        "operationId": "postReprintRequestsIdDecision",
        "tags": [
          "Stickers and reprints"
        ],
        "summary": "Approve (revokes the old token, issues a new one, Not printed) or reject (reason required; previous status restored)",
        "description": "Roles: Super Admin, Chain Admin. SRS: FR-QR-011, BR-04, BR-05, BR-06, NFR-REL-001.",
        "x-roles": [
          "Super Admin",
          "Chain Admin"
        ],
        "x-srs": [
          "FR-QR-011",
          "BR-04",
          "BR-05",
          "BR-06",
          "NFR-REL-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, status, reason, decisionReason, originalStickerStatus, device: { id, deviceCode, label, stickerStatus }, branch, client, requestedBy, reviewedBy, createdAt, decidedAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; REQUEST_CLOSED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "APPROVE",
                      "REJECT"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500,
                    "description": "Required when decision matches (see endpoint docs)"
                  }
                },
                "required": [
                  "decision"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/issues": {
      "get": {
        "operationId": "getIssues",
        "tags": [
          "Issues"
        ],
        "summary": "Issues in scope, paged and sorted; print=1 for a statement",
        "description": "Roles: Chain Admin, Branch Admin, Chain Engineer, Owner, Technician. SRS: FR-IS-002, FR-IS-006, UI-030-1.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Chain Engineer",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-IS-002",
          "FR-IS-006",
          "UI-030-1"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "RAISED",
                "PENDING",
                "SOLVED",
                "REMOVED"
              ]
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [{ id, code, title, description, status: RAISED|PENDING|SOLVED|REMOVED, audience, device: { id, deviceCode, label, status }, branch, client, raisedBy, handledBy, resolutionNote, createdAt, pendingAt, solvedAt, removedAt }], total, page, pageSize } | print=1: { items, total, truncated, statement: { ..., summary } }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postIssues",
        "tags": [
          "Issues"
        ],
        "summary": "Raise an issue about an active device",
        "description": "Roles: Branch Admin, Owner. SRS: FR-IS-001, BR-10.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-IS-001",
          "BR-10"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, code, title, description, status: RAISED|PENDING|SOLVED|REMOVED, audience, device: { id, deviceCode, label, status }, branch, client, raisedBy, handledBy, resolutionNote, createdAt, pendingAt, solvedAt, removedAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; DEVICE_RETIRED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deviceId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 150
                  },
                  "description": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 2000
                  }
                },
                "required": [
                  "deviceId",
                  "title",
                  "description"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/summary": {
      "get": {
        "operationId": "getIssuesSummary",
        "tags": [
          "Issues"
        ],
        "summary": "Raised, pending, solved and removed counts, and the branches to filter by",
        "description": "Roles: Chain Admin, Branch Admin, Chain Engineer, Owner, Technician. SRS: FR-IS-006.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Chain Engineer",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-IS-006"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "RAISED",
                "PENDING",
                "SOLVED",
                "REMOVED"
              ]
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ counts: { RAISED, PENDING, SOLVED, REMOVED }, branches: [{ id, name }] }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/export": {
      "get": {
        "operationId": "getIssuesExport",
        "tags": [
          "Issues"
        ],
        "summary": "The filtered issue list as CSV",
        "description": "Roles: Chain Admin, Branch Admin, Chain Engineer, Owner, Technician. SRS: FR-IS-006.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Chain Engineer",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-IS-006"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "RAISED",
                "PENDING",
                "SOLVED",
                "REMOVED"
              ]
            }
          },
          {
            "name": "branchId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv file"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/{id}": {
      "get": {
        "operationId": "getIssuesId",
        "tags": [
          "Issues"
        ],
        "summary": "One issue in scope",
        "description": "Roles: Chain Admin, Branch Admin, Chain Engineer, Owner, Technician. SRS: FR-IS-002, BR-17.",
        "x-roles": [
          "Chain Admin",
          "Branch Admin",
          "Chain Engineer",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-IS-002",
          "BR-17"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, code, title, description, status: RAISED|PENDING|SOLVED|REMOVED, audience, device: { id, deviceCode, label, status }, branch, client, raisedBy, handledBy, resolutionNote, createdAt, pendingAt, solvedAt, removedAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/{id}/withdraw": {
      "post": {
        "operationId": "postIssuesIdWithdraw",
        "tags": [
          "Issues"
        ],
        "summary": "The raiser withdraws an issue while it is Raised (status Removed)",
        "description": "Roles: Branch Admin, Owner. SRS: FR-IS-003.",
        "x-roles": [
          "Branch Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-IS-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, code, title, description, status: RAISED|PENDING|SOLVED|REMOVED, audience, device: { id, deviceCode, label, status }, branch, client, raisedBy, handledBy, resolutionNote, createdAt, pendingAt, solvedAt, removedAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; NOT_RAISER 403; ISSUE_NOT_RAISED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/{id}/status": {
      "patch": {
        "operationId": "patchIssuesIdStatus",
        "tags": [
          "Issues"
        ],
        "summary": "Start work (Raised to Pending)",
        "description": "Roles: Technician. SRS: FR-IS-004.",
        "x-roles": [
          "Technician"
        ],
        "x-srs": [
          "FR-IS-004"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ id, code, title, description, status: RAISED|PENDING|SOLVED|REMOVED, audience, device: { id, deviceCode, label, status }, branch, client, raisedBy, handledBy, resolutionNote, createdAt, pendingAt, solvedAt, removedAt }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; ISSUE_NOT_RAISED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "PENDING"
                    ]
                  }
                },
                "required": [
                  "status"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/issues/{id}/resolve": {
      "post": {
        "operationId": "postIssuesIdResolve",
        "tags": [
          "Issues"
        ],
        "summary": "Solve: the scanned or typed code must be the issue's device; adds the service record in the same step",
        "description": "Roles: Technician. SRS: FR-IS-005, BR-14, NFR-REL-001.",
        "x-roles": [
          "Technician"
        ],
        "x-srs": [
          "FR-IS-005",
          "BR-14",
          "NFR-REL-001"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "200": {
            "description": "{ issue: { id, code, title, description, status: RAISED|PENDING|SOLVED|REMOVED, audience, device: { id, deviceCode, label, status }, branch, client, raisedBy, handledBy, resolutionNote, createdAt, pendingAt, solvedAt, removedAt }, serviceRecords }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; DEVICE_NOT_FOUND 404; ISSUE_NOT_PENDING 409; NOT_HANDLER 403; DEVICE_MISMATCH 409; DEVICE_RETIRED 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{16,64}$"
                  },
                  "deviceCode": {
                    "type": "string",
                    "maxLength": 24
                  },
                  "description": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 2000
                  },
                  "submissionKey": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{8,100}$"
                  }
                },
                "required": [
                  "description"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/ledger": {
      "get": {
        "operationId": "getLedger",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Client ledger in scope with running balance; print=1 for a statement",
        "description": "Roles: Super Admin, Chain Admin, Owner. SRS: FR-PL-001, FR-PL-006, UI-030-4.",
        "x-roles": [
          "Super Admin",
          "Chain Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-PL-001",
          "FR-PL-006",
          "UI-030-4"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACCRUAL",
                "SETTLEMENT",
                "ADJUSTMENT",
                "REVERSAL"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [{ id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }], total, page, pageSize, totals: { added, deducted, net, balance } } | print=1: { items (oldest first, max 2000), total, truncated, totals, statement: { reference, printedAt, printedBy, filters, title, from, to, opening, accrued, settled, adjustments, closing, entries } }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/ledger/aging": {
      "get": {
        "operationId": "getLedgerAging",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Clients' outstanding points aged 0-30, 31-60, 61-90, 90+ days (settlements applied to the oldest points first)",
        "description": "Roles: Super Admin. SRS: FR-PL-007.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-PL-007"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "[{ clientId, clientName, clientType, outstanding, days0to30, days31to60, days61to90, over90 }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/ledger/export": {
      "get": {
        "operationId": "getLedgerExport",
        "tags": [
          "Points ledgers"
        ],
        "summary": "The filtered client ledger as CSV or PDF (format=csv|pdf)",
        "description": "Roles: Super Admin, Chain Admin, Owner. SRS: FR-PL-009.",
        "x-roles": [
          "Super Admin",
          "Chain Admin",
          "Owner"
        ],
        "x-srs": [
          "FR-PL-009"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACCRUAL",
                "SETTLEMENT",
                "ADJUSTMENT",
                "REVERSAL"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "csv",
                "pdf"
              ],
              "default": "csv"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {}
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {}
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv or application/pdf file"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/ledger/settlements": {
      "post": {
        "operationId": "postLedgerSettlements",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Record a client settlement of a positive number of points (never below zero)",
        "description": "Roles: Super Admin. SRS: FR-PL-003, FR-PL-004, FR-PL-008, BR-09, BR-18.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-PL-003",
          "FR-PL-004",
          "FR-PL-008",
          "BR-09",
          "BR-18"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BALANCE_BELOW_ZERO 409; VALIDATION_ERROR 400 (card or bank numbers)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "clientId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "points": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "remark": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "externalReference": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "clientId",
                  "points",
                  "remark"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/ledger/adjustments": {
      "post": {
        "operationId": "postLedgerAdjustments",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Record a signed client adjustment with a reason",
        "description": "Roles: Super Admin. SRS: FR-PL-003, FR-PL-008, BR-08, BR-18.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-PL-003",
          "FR-PL-008",
          "BR-08",
          "BR-18"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BALANCE_BELOW_ZERO 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "clientId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "points": {
                    "type": "integer",
                    "minimum": -100000000,
                    "maximum": 100000000
                  },
                  "remark": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "externalReference": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "clientId",
                  "points",
                  "remark"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/ledger/{id}/reverse": {
      "post": {
        "operationId": "postLedgerIdReverse",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Reverse one client-ledger entry (once only, with a reason)",
        "description": "Roles: Super Admin. SRS: FR-PL-005, BR-08, BR-09.",
        "x-roles": [
          "Super Admin"
        ],
        "x-srs": [
          "FR-PL-005",
          "BR-08",
          "BR-09"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; ALREADY_REVERSED 409; CANNOT_REVERSE_REVERSAL 409; BALANCE_BELOW_ZERO 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                },
                "required": [
                  "reason"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/bg-ledger": {
      "get": {
        "operationId": "getBgLedger",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Business Group ledger (Super Admin: own group); print=1 for a statement",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-PL-001, FR-PL-006, UI-030-4.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-PL-001",
          "FR-PL-006",
          "UI-030-4"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                25,
                50,
                100
              ]
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "print",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1",
                "true",
                "false"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "May be empty"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACCRUAL",
                "SETTLEMENT",
                "ADJUSTMENT",
                "REVERSAL"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "businessGroupId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ items: [{ id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }], total, page, pageSize, totals: { added, deducted, net, balance } } | print=1: { items (oldest first, max 2000), total, truncated, totals, statement: { reference, printedAt, printedBy, filters, title, from, to, opening, accrued, settled, adjustments, closing, entries } }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/bg-ledger/export": {
      "get": {
        "operationId": "getBgLedgerExport",
        "tags": [
          "Points ledgers"
        ],
        "summary": "The filtered Business Group ledger as CSV or PDF (format=csv|pdf)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-PL-009.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-PL-009"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACCRUAL",
                "SETTLEMENT",
                "ADJUSTMENT",
                "REVERSAL"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "businessGroupId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "csv",
                "pdf"
              ],
              "default": "csv"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {}
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {}
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv or application/pdf file"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/bg-ledger/settlements": {
      "post": {
        "operationId": "postBgLedgerSettlements",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Record a Business Group settlement (never below zero)",
        "description": "Roles: Supreme Admin. SRS: FR-PL-003, FR-PL-004, BR-09, BR-18.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-PL-003",
          "FR-PL-004",
          "BR-09",
          "BR-18"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BALANCE_BELOW_ZERO 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "businessGroupId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "points": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "remark": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "externalReference": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "businessGroupId",
                  "points",
                  "remark"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/bg-ledger/adjustments": {
      "post": {
        "operationId": "postBgLedgerAdjustments",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Record a signed Business Group adjustment with a reason",
        "description": "Roles: Supreme Admin. SRS: FR-PL-003, BR-08, BR-18.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-PL-003",
          "BR-08",
          "BR-18"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; BALANCE_BELOW_ZERO 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "businessGroupId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "points": {
                    "type": "integer",
                    "minimum": -100000000,
                    "maximum": 100000000
                  },
                  "remark": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "externalReference": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "May be empty"
                  }
                },
                "required": [
                  "businessGroupId",
                  "points",
                  "remark"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/bg-ledger/{id}/reverse": {
      "post": {
        "operationId": "postBgLedgerIdReverse",
        "tags": [
          "Points ledgers"
        ],
        "summary": "Reverse one Business Group ledger entry (once only)",
        "description": "Roles: Supreme Admin. SRS: FR-PL-005, BR-09.",
        "x-roles": [
          "Supreme Admin"
        ],
        "x-srs": [
          "FR-PL-005",
          "BR-09"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Value of the edmrs_csrf cookie"
          }
        ],
        "responses": {
          "201": {
            "description": "201 { id, businessGroupId, businessGroupName, clientId, clientName, deviceId, deviceCode, entryType, points, remark, externalReference, originalEntryId, reversedBy, createdBy, createdAt, runningBalance }"
          },
          "default": {
            "description": "Error envelope. NOT_FOUND 404; ALREADY_REVERSED 409; CANNOT_REVERSE_REVERSAL 409; BALANCE_BELOW_ZERO 409",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                },
                "required": [
                  "reason"
                ],
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/api/v1/dashboard": {
      "get": {
        "operationId": "getDashboard",
        "tags": [
          "Dashboard and audit"
        ],
        "summary": "Role-specific figures, all computed from stored data",
        "description": "Roles: Supreme Admin, Super Admin, Chain Admin, Branch Admin, Owner, Technician. SRS: FR-DB-001, FR-DB-002, FR-DB-003, FR-DB-004, FR-DB-005, FR-DB-006, BR-11.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin",
          "Chain Admin",
          "Branch Admin",
          "Owner",
          "Technician"
        ],
        "x-srs": [
          "FR-DB-001",
          "FR-DB-002",
          "FR-DB-003",
          "FR-DB-004",
          "FR-DB-005",
          "FR-DB-006",
          "BR-11"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "{ role, generatedAt, figures } - Supreme Admin: { regions, businessGroups, chains, individualOwners, devices, superAdmins, pointsByBusinessGroup: [{ id, name, status, accrued, outstanding }] }; Super Admin: { chains, individualOwners, technicians, devices, stickersToPrint, stickersToDeliver, pendingSignUps, pendingReprintRequests, clientPointsOutstanding, pointsOwedToCompany }; Chain Admin: { branches, devices, openIssues, serviceVisitsLast30Days, branchAdmins, technicians, pointsOutstanding, pendingReprintRequests, stickersToPrint }; Branch Admin / Owner: { devices, activeDevices, openIssues, serviceRecords, stickers: { NOT_PRINTED, PRINTED, DELIVERED, REPRINT_REQUESTED }, pointsOutstanding (Owner) }; Technician: { openIssues, myPendingIssues, serviceVisitsThisMonth }"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/audit-logs": {
      "get": {
        "operationId": "getAuditLogs",
        "tags": [
          "Dashboard and audit"
        ],
        "summary": "Newest 500 audit entries matching the filters (Super Admin: own group)",
        "description": "Roles: Supreme Admin, Super Admin. SRS: FR-AL-002, FR-AL-003.",
        "x-roles": [
          "Supreme Admin",
          "Super Admin"
        ],
        "x-srs": [
          "FR-AL-002",
          "FR-AL-003"
        ],
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "actor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 190
            }
          },
          {
            "name": "entityType",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "entityId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "action",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "[{ id, actor: { id, name, email, role } | null, businessGroupId, entityType, entityId, action, details, ipAddress, createdAt }]"
          },
          "default": {
            "description": "Error envelope. ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
