{
    "schemes": [],
    "swagger": "2.0",
    "info": {
        "description": "Identity and authentication management service for Banknote Tracker",
        "title": "BNT Identity Service API",
        "contact": {},
        "version": "1.0"
    },
    "host": "localhost:9002",
    "basePath": "/",
    "paths": {
        "/identity/health": {
            "get": {
                "description": "Returns service health status",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "health"
                ],
                "summary": "Health check",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.HealthResponse"
                        }
                    }
                }
            }
        },
        "/identity/invites/{reference}/resend": {
            "post": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Regenerates the token and expiry on an existing pending or expired invite and re-sends the accept email. Only super_admin or organisation_admin may resend; an accepted or revoked invite cannot be resent.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "invites"
                ],
                "summary": "Resend an invite",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Invite reference",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/dto.CreateInviteResultDTO"
                        }
                    },
                    "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"
                        }
                    }
                }
            }
        },
        "/identity/lock": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Locks or unlocks a user account. Restricted to admin and super_admin roles.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "identity"
                ],
                "summary": "Toggle account lock",
                "parameters": [
                    {
                        "description": "Lock request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.LockRequest"
                        }
                    }
                ],
                "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"
                        }
                    }
                }
            }
        },
        "/identity/me": {
            "get": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Returns the identity details of the currently authenticated user",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "identity"
                ],
                "summary": "Get current identity",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.IdentityResponse"
                        }
                    },
                    "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"
                        }
                    }
                }
            }
        },
        "/identity/mfa": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Enables or disables multi-factor authentication for the authenticated user",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "identity"
                ],
                "summary": "Toggle MFA",
                "parameters": [
                    {
                        "description": "MFA request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.MfaRequest"
                        }
                    }
                ],
                "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"
                        }
                    }
                }
            }
        },
        "/identity/password/reset": {
            "post": {
                "description": "Starts the password reset flow by sending an OTP to the user's email",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "password"
                ],
                "summary": "Initiate password reset",
                "parameters": [
                    {
                        "description": "Email request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.EmailRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.OtpReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/identity/password/{otp_reference}": {
            "post": {
                "description": "Completes signup or password reset by setting the user's password and returning login tokens",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "password"
                ],
                "summary": "Set password",
                "parameters": [
                    {
                        "type": "string",
                        "description": "OTP reference (UUID)",
                        "name": "otp_reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "type": "boolean",
                        "description": "Whether this is an invite flow",
                        "name": "invite",
                        "in": "query"
                    },
                    {
                        "description": "Set password request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.SetPasswordRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.LoginResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/identity/password/{otp_reference}/change": {
            "post": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Changes the password for the authenticated user using OTP verification",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "password"
                ],
                "summary": "Change password",
                "parameters": [
                    {
                        "type": "string",
                        "description": "OTP reference (UUID)",
                        "name": "otp_reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "description": "Change password request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.ChangePasswordRequest"
                        }
                    }
                ],
                "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"
                        }
                    }
                }
            }
        },
        "/identity/reactivate": {
            "post": {
                "description": "Initiates account reactivation by sending an OTP to the user's email",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "identity"
                ],
                "summary": "Reactivate account",
                "parameters": [
                    {
                        "description": "Email request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.EmailRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/schemas.OtpReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/identity/signup": {
            "post": {
                "description": "Initiates the signup flow by creating a new identity and sending OTP verification",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "identity"
                ],
                "summary": "Sign up a new user",
                "parameters": [
                    {
                        "description": "Sign up request",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.SignUpRequest"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Created",
                        "schema": {
                            "$ref": "#/definitions/schemas.ReferenceResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "409": {
                        "description": "Conflict",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    },
                    "500": {
                        "description": "Internal Server Error",
                        "schema": {
                            "$ref": "#/definitions/shared.ApplicationError"
                        }
                    }
                }
            }
        },
        "/identity/{reference}/role": {
            "put": {
                "security": [
                    {
                        "BearerAuth": []
                    }
                ],
                "description": "Changes a target user's role (user/admin/organisation_admin/\nsuper_admin). Authorization is layered: only super_admin may\ngrant super_admin; admin/organisation_admin are scoped to their\nown organisation and cannot modify a super_admin; nobody may\nchange their own role. On success the user's active sessions are\nrevoked (refresh blocked); their current access token keeps the\nold role only until it expires, after which re-login applies the\nnew role.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "identity"
                ],
                "summary": "Change a user's role",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Target user reference (UUID)",
                        "name": "reference",
                        "in": "path",
                        "required": true
                    },
                    {
                        "description": "New role",
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/schemas.ChangeRoleRequest"
                        }
                    }
                ],
                "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"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "dto.CreateInviteResultDTO": {
            "type": "object",
            "properties": {
                "email": {
                    "type": "string"
                },
                "expires_at_timestamp": {
                    "type": "string"
                },
                "reference": {
                    "type": "string"
                },
                "token": {
                    "type": "string"
                }
            }
        },
        "models.LocationInfo": {
            "type": "object",
            "properties": {
                "city": {
                    "type": "string"
                },
                "country": {
                    "type": "string"
                },
                "country_code": {
                    "type": "string"
                },
                "lat": {
                    "type": "number"
                },
                "lon": {
                    "type": "number"
                },
                "region": {
                    "type": "string"
                }
            }
        },
        "models.Module": {
            "type": "object",
            "properties": {
                "key": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                },
                "sub_modules": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.Module"
                    }
                }
            }
        },
        "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.ChangePasswordRequest": {
            "type": "object",
            "required": [
                "confirm_new_password",
                "new_password",
                "old_password"
            ],
            "properties": {
                "confirm_new_password": {
                    "type": "string"
                },
                "new_password": {
                    "type": "string",
                    "minLength": 6
                },
                "old_password": {
                    "type": "string"
                }
            }
        },
        "schemas.ChangeRoleRequest": {
            "type": "object",
            "required": [
                "role"
            ],
            "properties": {
                "role": {
                    "type": "string",
                    "enum": [
                        "user",
                        "admin",
                        "organisation_admin",
                        "super_admin"
                    ]
                }
            }
        },
        "schemas.EmailRequest": {
            "type": "object",
            "required": [
                "email"
            ],
            "properties": {
                "email": {
                    "type": "string"
                }
            }
        },
        "schemas.HealthResponse": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                }
            }
        },
        "schemas.IdentityResponse": {
            "type": "object",
            "properties": {
                "accessible_modules": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.Module"
                    }
                },
                "created_by": {
                    "$ref": "#/definitions/schemas.AuditInfoResponse"
                },
                "department_name": {
                    "type": "string"
                },
                "department_reference": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "is_locked": {
                    "type": "boolean"
                },
                "is_onboarding_complete": {
                    "type": "boolean"
                },
                "is_verified_email": {
                    "type": "boolean"
                },
                "is_verified_phone": {
                    "type": "boolean"
                },
                "location_code": {
                    "type": "string"
                },
                "login_attempts": {
                    "type": "integer"
                },
                "mfa_channel": {
                    "type": "string"
                },
                "mfa_enabled": {
                    "type": "boolean"
                },
                "organisation_name": {
                    "type": "string"
                },
                "organisation_reference": {
                    "type": "string"
                },
                "reference": {
                    "type": "string"
                },
                "role": {
                    "type": "string"
                },
                "signup_status": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": {
                            "type": "string"
                        }
                    }
                },
                "updated_by": {
                    "$ref": "#/definitions/schemas.AuditInfoResponse"
                }
            }
        },
        "schemas.LockRequest": {
            "type": "object",
            "properties": {
                "is_locked": {
                    "type": "boolean"
                }
            }
        },
        "schemas.LoginResponse": {
            "type": "object",
            "properties": {
                "access_token": {
                    "type": "string"
                },
                "department_reference": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "expires_at_timestamp": {
                    "type": "string"
                },
                "id_token": {
                    "type": "string"
                },
                "is_onboarding_complete": {
                    "type": "boolean"
                },
                "organisation_reference": {
                    "type": "string"
                },
                "reference": {
                    "type": "string"
                },
                "refresh_token": {
                    "type": "string"
                },
                "role": {
                    "type": "string"
                },
                "session_reference": {
                    "type": "string"
                }
            }
        },
        "schemas.MfaRequest": {
            "type": "object",
            "required": [
                "mfa_channel",
                "mfa_enabled"
            ],
            "properties": {
                "mfa_channel": {
                    "type": "string",
                    "enum": [
                        "email"
                    ]
                },
                "mfa_enabled": {
                    "type": "boolean"
                }
            }
        },
        "schemas.OtpReferenceResponse": {
            "type": "object",
            "properties": {
                "otp_reference": {
                    "type": "string"
                }
            }
        },
        "schemas.ReferenceResponse": {
            "type": "object",
            "properties": {
                "reference": {
                    "type": "string"
                }
            }
        },
        "schemas.SetPasswordRequest": {
            "type": "object",
            "required": [
                "confirm_password",
                "email",
                "password"
            ],
            "properties": {
                "confirm_password": {
                    "type": "string"
                },
                "department_reference": {
                    "type": "string"
                },
                "device_fingerprint": {
                    "type": "string"
                },
                "device_reference": {
                    "description": "Role is intentionally NOT accepted from the client. It is determined server side: an invite's\npre-assigned role, or \"user\" for self signup. This removes any self-assign-role path.",
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "invite_token": {
                    "description": "InviteToken is the raw token from the invite email. Required when accepting an invite\n(?invite=true): the invite reference and email alone are not proof of having the email.",
                    "type": "string"
                },
                "location": {
                    "$ref": "#/definitions/models.LocationInfo"
                },
                "organisation_reference": {
                    "type": "string"
                },
                "password": {
                    "type": "string",
                    "minLength": 6
                }
            }
        },
        "schemas.SignUpRequest": {
            "type": "object",
            "required": [
                "email"
            ],
            "properties": {
                "channel": {
                    "type": "string",
                    "enum": [
                        "email",
                        "sms"
                    ]
                },
                "email": {
                    "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"
        }
    }
}