{
    "schemes": [],
    "swagger": "2.0",
    "info": {
        "description": "User management service for Banknote Tracker",
        "title": "BNT User Service API",
        "contact": {},
        "version": "1.0"
    },
    "host": "localhost:9001",
    "basePath": "/",
    "paths": {
        "/users": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns a paginated list of users with optional filtering and sorting. Restricted to admin, super_admin, and organisation_admin roles.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "List users",
                "parameters": [
                    {
                        "type": "integer",
                        "default": 1,
                        "description": "Page number",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "default": 0,
                        "description": "Page size override",
                        "name": "page_size",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "default": "created_at_timestamp",
                        "description": "Sort field",
                        "name": "sort_by",
                        "in": "query"
                    },
                    {
                        "enum": [
                            "asc",
                            "desc"
                        ],
                        "type": "string",
                        "default": "desc",
                        "description": "Sort order",
                        "name": "order_by",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.PaginatedUserResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Submits the authenticated user's profile changes for approval\n(maker-checker). The changes are NOT applied immediately —\nthey are stored as a pending change request and only take\neffect once an admin (admin/super_admin/organisation_admin)\napproves via PUT /users/change-requests/{reference}/approve.\n\nThe business rules (org/dept one-change rule, name one-change\nrule, and the name-collision check) are enforced at approval\ntime, not at submission. Submitting again while a request is\nalready pending supersedes the previous one (latest wins).",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Submit own profile change (pending approval)",
                "parameters": [
                    {
                        "description": "Update user request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.UpdateUserRequest"
                        }
                    }
                ],
                "responses": {
                    "202": {
                        "description": "Accepted",
                        "schema": {
                            "$ref": "#/definitions/schemas.SubmitChangeRequestResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "post": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Creates a new user profile for the authenticated identity. Accepts JSON or multipart/form-data with an optional photo.",
                "consumes": [
                    "application/json",
                    "multipart/form-data"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Create a new user",
                "parameters": [
                    {
                        "description": "Create user request (JSON)",
                        "name": "body",
                        "in": "body",
                        "schema": {
                            "$ref": "#/definitions/schemas.CreateUserRequest"
                        }
                    },
                    {
                        "type": "string",
                        "description": "First name (multipart)",
                        "name": "first_name",
                        "in": "formData"
                    },
                    {
                        "type": "string",
                        "description": "Last name (multipart)",
                        "name": "last_name",
                        "in": "formData"
                    },
                    {
                        "type": "string",
                        "description": "Mobile number (multipart)",
                        "name": "mobile_number",
                        "in": "formData"
                    },
                    {
                        "type": "file",
                        "description": "Profile photo (JPEG or PNG, max 5MB)",
                        "name": "photo",
                        "in": "formData"
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Created",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/change-requests": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Lists profile change requests. admin/organisation_admin see only\ntheir own organisation's requests; super_admin sees all. Filter\nby status with ?status=pending|approved|rejected|superseded.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "change-requests"
                ],
                "summary": "List change requests (admin)",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Filter by status",
                        "name": "status",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "default": 1,
                        "description": "Page number",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "default": 0,
                        "description": "Page size override",
                        "name": "page_size",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "default": "created_at",
                        "description": "Sort field",
                        "name": "sort_by",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "default": "desc",
                        "description": "Sort order",
                        "name": "order_by",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.PaginatedChangeRequestResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/change-requests/{reference}": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns a single change request with the field-by-field diff.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "change-requests"
                ],
                "summary": "Get a change request (admin)",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Change request reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ChangeRequestResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/change-requests/{reference}/approve": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Approves a pending change request and applies the changes to the\nuser via the normal update path (one-change rule + name-collision\ncheck run now). review_comment is optional.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "change-requests"
                ],
                "summary": "Approve a change request (admin)",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Change request reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "description": "Optional review comment",
                        "name": "body",
                        "in": "body",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReviewChangeRequestRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "409": {
                        "description": "Conflict",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/change-requests/{reference}/reject": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Rejects a pending change request. Nothing is applied. A\nreview_comment is required.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "change-requests"
                ],
                "summary": "Reject a change request (admin)",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Change request reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "description": "Rejection reason",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.ReviewChangeRequestRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "409": {
                        "description": "Conflict",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/consent-preferences": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Updates privacy and consent preferences for the authenticated user",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "preferences"
                ],
                "summary": "Update consent preferences",
                "parameters": [
                    {
                        "description": "Consent preference request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.ConsentPreferenceRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/email/{email}": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns a user profile by their email address. Restricted to admin, super_admin, and organisation_admin roles.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Get user by email",
                "parameters": [
                    {
                        "type": "string",
                        "description": "User email address",
                        "name": "email",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.UserResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/health": {
            "get": {
                "description": "Returns service health status",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "health"
                ],
                "summary": "Health check",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.HealthResponse"
                        }
                    }
                }
            }
        },
        "/users/me": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns the profile of the currently authenticated user",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Get current user",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.UserResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/me/change-request": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns the authenticated user's most recent profile change request (any status).",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "change-requests"
                ],
                "summary": "Get my latest change request",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ChangeRequestResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/photo": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Uploads a profile photo for the authenticated user. Accepts JPEG or PNG (max 5MB).",
                "consumes": [
                    "multipart/form-data"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Upload user photo",
                "parameters": [
                    {
                        "type": "file",
                        "description": "Photo file (JPEG or PNG, max 5MB)",
                        "name": "photo",
                        "in": "formData",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "delete": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Deletes the profile photo for the authenticated user. Succeeds even when no photo is stored; the user then shows their default avatar.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Delete user photo",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/user-preferences": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Updates notification preferences for the authenticated user",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "preferences"
                ],
                "summary": "Update user preferences",
                "parameters": [
                    {
                        "description": "User preference request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.UserPreferenceRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/{reference}": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns a user profile by their unique reference",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Get user by reference",
                "parameters": [
                    {
                        "type": "string",
                        "description": "User reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.UserResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Admin-only endpoint to update another user's profile —\nincluding their organisation_reference and\ndepartment_reference. Only admin, super_admin, and\norganisation_admin roles can call it. admin and\norganisation_admin can only update users that belong to\ntheir own organisation; super_admin can update any user\nin any organisation. The same field validation rules as\nthe self-update endpoint apply (UUID format, existence\ncheck on org/dept references).\n\nThis endpoint bypasses the one-change credits for both\norg/dept and names — admins can rename users freely.\nHowever, the name-collision check still applies: a name\nchange to a (first_name, last_name) pair already in use\nby another user is rejected with 409.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Admin: update any user",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Target user reference",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "description": "Update user request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.UpdateUserRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "delete": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Deletes a user by their reference. Restricted to admin and super_admin roles.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Delete user",
                "parameters": [
                    {
                        "type": "string",
                        "description": "User reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/users/{reference}/photo": {
            "get": {
                "description": "Returns the profile photo for the specified user",
                "produces": [
                    "image/jpeg",
                    "image/png"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Get user photo",
                "parameters": [
                    {
                        "type": "string",
                        "description": "User reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Photo file"
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Uploads/replaces the profile photo of the user identified by reference. Privileged roles only.",
                "consumes": [
                    "multipart/form-data"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Upload a photo for a specific user (admin)",
                "parameters": [
                    {
                        "type": "string",
                        "description": "User reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "type": "file",
                        "description": "Photo file (JPEG or PNG, max 5MB)",
                        "name": "photo",
                        "in": "formData",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            },
            "delete": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Removes the profile photo of the user identified by reference. Privileged roles only. Succeeds even when no photo is stored; the user then shows their default avatar.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "users"
                ],
                "summary": "Delete a specific user's photo (admin)",
                "parameters": [
                    {
                        "type": "string",
                        "description": "User reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "403": {
                        "description": "Forbidden",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "models.ConsentPreferences": {
            "type": "object",
            "properties": {
                "accepted_cookies": {
                    "type": "boolean"
                },
                "accepted_data_protection": {
                    "type": "boolean"
                },
                "accepted_privacy": {
                    "type": "boolean"
                },
                "accepted_terms": {
                    "type": "boolean"
                },
                "functional": {
                    "type": "boolean"
                },
                "marketing": {
                    "type": "boolean"
                }
            }
        },
        "models.Module": {
            "type": "object",
            "properties": {
                "key": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                },
                "sub_modules": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.Module"
                    }
                }
            }
        },
        "models.UserPreferences": {
            "type": "object",
            "properties": {
                "email_notifications": {
                    "type": "boolean"
                },
                "notification_freq": {
                    "type": "string"
                },
                "push_notifications": {
                    "type": "boolean"
                }
            }
        },
        "schemas.AuditInfoResponse": {
            "type": "object",
            "properties": {
                "department_name": {
                    "type": "string"
                },
                "department_reference": {
                    "type": "string"
                },
                "device_name": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "full_name": {
                    "type": "string"
                },
                "ip_address": {
                    "type": "string"
                },
                "latitude": {
                    "type": "string"
                },
                "longitude": {
                    "type": "string"
                },
                "organisation_name": {
                    "type": "string"
                },
                "organisation_reference": {
                    "type": "string"
                },
                "photo_url": {
                    "type": "string"
                },
                "role": {
                    "type": "string"
                },
                "timestamp": {
                    "type": "string"
                },
                "user_reference": {
                    "type": "string"
                }
            }
        },
        "schemas.ChangeFieldsResponse": {
            "type": "object",
            "properties": {
                "department_reference": {
                    "type": "string"
                },
                "first_name": {
                    "type": "string"
                },
                "last_name": {
                    "type": "string"
                },
                "mobile_number": {
                    "type": "string"
                },
                "organisation_reference": {
                    "type": "string"
                }
            }
        },
        "schemas.ChangeRequestResponse": {
            "type": "object",
            "properties": {
                "changes": {
                    "$ref": "#/definitions/schemas.ChangeFieldsResponse"
                },
                "created_at": {
                    "type": "string"
                },
                "current": {
                    "$ref": "#/definitions/schemas.ChangeFieldsResponse"
                },
                "reference": {
                    "type": "string"
                },
                "requested_by": {
                    "$ref": "#/definitions/schemas.AuditInfoResponse"
                },
                "review_comment": {
                    "type": "string"
                },
                "reviewed_at": {
                    "type": "string"
                },
                "reviewed_by": {
                    "$ref": "#/definitions/schemas.AuditInfoResponse"
                },
                "status": {
                    "type": "string"
                },
                "user_reference": {
                    "type": "string"
                }
            }
        },
        "schemas.ConsentPreferenceRequest": {
            "type": "object",
            "required": [
                "accepted_cookies",
                "accepted_data_protection",
                "accepted_privacy",
                "accepted_terms"
            ],
            "properties": {
                "accepted_cookies": {
                    "type": "boolean"
                },
                "accepted_data_protection": {
                    "type": "boolean"
                },
                "accepted_privacy": {
                    "type": "boolean"
                },
                "accepted_terms": {
                    "type": "boolean"
                },
                "functional": {
                    "type": "boolean"
                },
                "marketing": {
                    "type": "boolean"
                }
            }
        },
        "schemas.CreateUserRequest": {
            "type": "object",
            "required": [
                "first_name",
                "last_name",
                "mobile_number"
            ],
            "properties": {
                "first_name": {
                    "type": "string",
                    "maxLength": 100,
                    "minLength": 2
                },
                "last_name": {
                    "type": "string",
                    "maxLength": 100,
                    "minLength": 2
                },
                "mobile_number": {
                    "type": "string"
                }
            }
        },
        "schemas.HealthResponse": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                }
            }
        },
        "schemas.PaginatedChangeRequestResponse": {
            "type": "object",
            "properties": {
                "items": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/schemas.ChangeRequestResponse"
                    }
                },
                "pagination": {
                    "$ref": "#/definitions/schemas.Pagination"
                }
            }
        },
        "schemas.PaginatedUserResponse": {
            "type": "object",
            "properties": {
                "items": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/schemas.UserResponse"
                    }
                },
                "pagination": {
                    "$ref": "#/definitions/schemas.Pagination"
                }
            }
        },
        "schemas.Pagination": {
            "type": "object",
            "properties": {
                "has_next": {
                    "type": "boolean"
                },
                "has_previous": {
                    "type": "boolean"
                },
                "page": {
                    "type": "integer"
                },
                "pages": {
                    "type": "integer"
                },
                "size": {
                    "type": "integer"
                },
                "total": {
                    "type": "integer"
                }
            }
        },
        "schemas.ReferenceResponse": {
            "type": "object",
            "properties": {
                "reference": {
                    "type": "string"
                }
            }
        },
        "schemas.ReviewChangeRequestRequest": {
            "type": "object",
            "properties": {
                "review_comment": {
                    "type": "string",
                    "maxLength": 500
                }
            }
        },
        "schemas.SubmitChangeRequestResponse": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                },
                "reference": {
                    "type": "string"
                },
                "status": {
                    "type": "string"
                }
            }
        },
        "schemas.UpdateUserRequest": {
            "type": "object",
            "properties": {
                "department_reference": {
                    "type": "string"
                },
                "first_name": {
                    "type": "string",
                    "maxLength": 100,
                    "minLength": 2
                },
                "last_name": {
                    "type": "string",
                    "maxLength": 100,
                    "minLength": 2
                },
                "mobile_number": {
                    "type": "string"
                },
                "organisation_reference": {
                    "type": "string"
                }
            }
        },
        "schemas.UserPreferenceRequest": {
            "type": "object",
            "properties": {
                "email_notifications": {
                    "type": "boolean"
                },
                "notification_freq": {
                    "type": "string",
                    "enum": [
                        "immediate",
                        "hourly",
                        "daily",
                        "weekly",
                        "monthly",
                        "never"
                    ]
                },
                "push_notifications": {
                    "type": "boolean"
                }
            }
        },
        "schemas.UserResponse": {
            "type": "object",
            "properties": {
                "accessible_modules": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.Module"
                    }
                },
                "consent_preferences": {
                    "$ref": "#/definitions/models.ConsentPreferences"
                },
                "created_by": {
                    "$ref": "#/definitions/schemas.AuditInfoResponse"
                },
                "department_name": {
                    "type": "string"
                },
                "department_reference": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "first_name": {
                    "type": "string"
                },
                "full_name": {
                    "type": "string"
                },
                "is_locked": {
                    "type": "boolean"
                },
                "is_verified_email": {
                    "type": "boolean"
                },
                "is_verified_phone": {
                    "type": "boolean"
                },
                "last_name": {
                    "type": "string"
                },
                "location_code": {
                    "type": "string"
                },
                "login_attempts": {
                    "type": "integer"
                },
                "mfa_enabled": {
                    "type": "boolean"
                },
                "mobile_number": {
                    "type": "string"
                },
                "name_change_used": {
                    "type": "boolean"
                },
                "name_normalised": {
                    "type": "string"
                },
                "org_dept_change_used": {
                    "type": "boolean"
                },
                "organisation_name": {
                    "type": "string"
                },
                "organisation_reference": {
                    "type": "string"
                },
                "photo_url": {
                    "type": "string"
                },
                "platform_owner": {
                    "description": "PlatformOwner is true only for members of the platform-owner org (Sytycc), from the JWT\nplatform_owner claim. Lets the UI gate all-organisation visibility on it.",
                    "type": "boolean"
                },
                "read_only": {
                    "description": "ReadOnly is true when the holder's department is observer (read-only), from the JWT read_only\nclaim. Lets the UI hide every action control; the backend independently enforces the write block.",
                    "type": "boolean"
                },
                "reference": {
                    "type": "string"
                },
                "role": {
                    "type": "string"
                },
                "signup_status": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": {
                            "type": "string"
                        }
                    }
                },
                "status": {
                    "type": "string"
                },
                "updated_by": {
                    "$ref": "#/definitions/schemas.AuditInfoResponse"
                },
                "user_preferences": {
                    "$ref": "#/definitions/models.UserPreferences"
                },
                "user_type": {
                    "description": "UserType is \"factory\" or \"platform\", from the JWT user_type claim (the org's factory flag).",
                    "type": "string"
                }
            }
        },
        "shared.ApplicationError": {
            "type": "object",
            "properties": {
                "error_reference": {
                    "type": "string"
                },
                "error_type": {
                    "$ref": "#/definitions/shared.ErrorType"
                },
                "errors": {
                    "type": "object",
                    "additionalProperties": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                },
                "status_code": {
                    "type": "integer"
                },
                "timestamp": {
                    "type": "string"
                }
            }
        },
        "shared.ErrorType": {
            "type": "string",
            "enum": [
                "VALIDATION_ERROR",
                "NOT_FOUND_ERROR",
                "CONFLICT_ERROR",
                "UNAUTHORIZED_ERROR",
                "AUTHENTICATION_ERROR",
                "FORBIDDEN_ERROR",
                "BAD_REQUEST_ERROR",
                "SERVER_ERROR",
                "REDIS_ERROR",
                "MONGO_DB_ERROR",
                "CREATE_ERROR",
                "UPDATE_ERROR",
                "INVALID_RESOURCE_ERROR",
                "TIMEOUT",
                "METHOD_NOT_ALLOWED",
                "RATE_LIMIT_EXCEEDED",
                "PAYLOAD_TOO_LARGE",
                "UNPROCESSABLE_ENTITY",
                "INTERNAL_ERROR"
            ],
            "x-enum-varnames": [
                "ValidationError",
                "NotFoundError",
                "ConflictError",
                "UnauthorizedError",
                "AuthenticationError",
                "ForbiddenError",
                "BadRequestError",
                "ServerError",
                "RedisError",
                "MongoDBError",
                "CreateError",
                "UpdateError",
                "InvalidResourceError",
                "TimeoutError",
                "MethodNotAllowedError",
                "RateLimitExceededError",
                "PayloadTooLargeError",
                "UnprocessableEntityError",
                "InternalError"
            ]
        }
    },
    "securityDefinitions": {
        "BearerAuth": {
            "type": "apiKey",
            "name": "Authorization",
            "in": "header"
        }
    }
}