{
  "openapi": "3.0.0",
  "info": {
    "title": "Users API",
    "version": "1.0.0",
    "description": "API for user management and authentication"
  },
  "tags": [
    {
      "name": "Registration",
      "description": "User registration operations"
    },
    {
      "name": "Users",
      "description": "User management operations"
    },
    {
      "name": "Credentials",
      "description": "Credential management operations"
    },
    {
      "name": "Password",
      "description": "Password management operations"
    }
  ],
  "paths": {
    "/v1/users/initiate-registration": {
      "post": {
        "summary": "Initiate registration",
        "description": "Start user registration process",
        "tags": ["Registration"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InitiateRegistrationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Registration initiated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InitiateRegistrationResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/v1/users/verify-registration": {
      "post": {
        "summary": "Verify registration",
        "description": "Verify registration OTP",
        "tags": ["Registration"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyRegistrationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Registration verified successfully"
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/v1/users": {
      "post": {
        "summary": "Create user",
        "description": "Create a new user",
        "tags": ["Users"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUserRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "get": {
        "summary": "List users",
        "description": "Get all users",
        "tags": ["Users"],
        "responses": {
          "200": {
            "description": "List of users",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/User"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/users/persona": {
      "post": {
        "summary": "Create user with persona",
        "description": "Create user with associated persona",
        "tags": ["Users"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUserWithPersonaRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User and persona created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserWithPersonaResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/v1/users/{id}": {
      "get": {
        "summary": "Get user",
        "description": "Get user by ID",
        "tags": ["Users"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      },
      "put": {
        "summary": "Update user",
        "description": "Update user by ID",
        "tags": ["Users"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateUserRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      },
      "delete": {
        "summary": "Delete user",
        "description": "Delete user by ID",
        "tags": ["Users"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User deleted successfully"
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    },
    "/v1/users/credentials": {
      "post": {
        "summary": "Add credential",
        "description": "Add new credential to user",
        "tags": ["Credentials"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddCredentialRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Credential added successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Credential"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "get": {
        "summary": "List credentials",
        "description": "Get all credentials",
        "tags": ["Credentials"],
        "responses": {
          "200": {
            "description": "List of credentials",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Credential"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/users/credentials/validate": {
      "post": {
        "summary": "Validate credential",
        "description": "Validate credential with OTP",
        "tags": ["Credentials"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ValidateCredentialRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Credential validated successfully"
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/v1/users/credentials/{cred_id}": {
      "put": {
        "summary": "Update credential",
        "description": "Update existing credential",
        "tags": ["Credentials"],
        "parameters": [
          {
            "name": "cred_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCredentialRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Credential updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Credential"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      },
      "delete": {
        "summary": "Delete credential",
        "description": "Delete credential by ID",
        "tags": ["Credentials"],
        "parameters": [
          {
            "name": "cred_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Credential deleted successfully"
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    },
    "/v1/users/{id}/password": {
      "put": {
        "summary": "Change password",
        "description": "Change user password",
        "tags": ["Password"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangePasswordRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password changed successfully"
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/v1/users/reset-password": {
      "post": {
        "summary": "Reset password",
        "description": "Reset forgotten password",
        "tags": ["Password"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResetPasswordRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password reset successfully"
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "InitiateRegistrationRequest": {
        "type": "object",
        "required": ["credential_type", "credential_value", "password", "terms_accepted", "privacy_policy_accepted"],
        "properties": {
          "credential_type": {
            "type": "string",
            "enum": ["email", "phone"]
          },
          "credential_value": {
            "type": "string"
          },
          "password": {
            "type": "string"
          },
          "terms_accepted": {
            "type": "boolean"
          },
          "privacy_policy_accepted": {
            "type": "boolean"
          }
        }
      },
      "InitiateRegistrationResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "user_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "VerifyRegistrationRequest": {
        "type": "object",
        "required": ["user_id", "credential_type", "otp"],
        "properties": {
          "user_id": {
            "type": "string",
            "format": "uuid"
          },
          "credential_type": {
            "type": "string",
            "enum": ["email", "phone"]
          },
          "otp": {
            "type": "string"
          }
        }
      },
      "CreateUserRequest": {
        "type": "object",
        "required": ["name", "password"],
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "password": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "lang": {
            "type": "string",
            "enum": ["en", "de", "fr", "it"]
          },
          "mfa_mode": {
            "type": "string",
            "enum": ["off", "email", "phone", "totp"]
          }
        }
      },
      "UpdateUserRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "lang": {
            "type": "string",
            "enum": ["en", "de", "fr", "it"]
          },
          "mfa_mode": {
            "type": "string",
            "enum": ["off", "email", "phone", "totp"]
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "lang": {
            "type": "string"
          },
          "mfa_mode": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "modified_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "ValidationError": {
        "description": "Invalid input data",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "users.invalid_user_input",
              "message": "Invalid user input data"
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "users.user_not_found",
              "message": "User not found"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ]
} 