use serde::{Deserialize, Serialize};
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
use validator::Validate;
#[derive(Debug, Serialize, Deserialize, Validate)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="Authentication request with email and password",
example = json!({
"email": "user@example.com",
"password": "SecurePassword123!"
})
))]
pub struct LoginRequest {
#[validate(email)]
#[cfg_attr(feature = "openapi", schema(example = "user@example.com", format = "email"))]
pub email: String,
#[validate(length(min = 1))]
#[cfg_attr(feature = "openapi", schema(example = "SecurePassword123!", min_length = 1))]
pub password: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="Login response containing authentication token and user information",
example = json!({
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user_id": "507f1f77bcf86cd799439011",
"agent_id": "agent_123",
"permissions": ["read:contacts", "write:contacts", "admin:account"],
"softphone_enabled": true
})
))]
pub struct LoginResponse {
pub success: bool,
#[cfg_attr(feature = "openapi", schema(example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."))]
pub token: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "507f1f77bcf86cd799439011"))]
pub user_id: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "agent_123"))]
pub agent_id: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = json!(["read:contacts", "write:contacts"])))]
pub permissions: Option<Vec<String>>,
#[cfg_attr(feature = "openapi", schema(example = "Invalid credentials"))]
pub error: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub softphone_enabled: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="Logout request with token or session ID"
))]
pub struct LogoutRequest {
#[cfg_attr(feature = "openapi", schema(example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."))]
pub token: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "sess_1234567890"))]
pub session_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Validate)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="Request to initiate password reset process",
example = json!({
"email": "user@example.com"
})
))]
pub struct PasswordResetRequest {
#[validate(email)]
#[cfg_attr(feature = "openapi", schema(example = "user@example.com", format = "email"))]
pub email: String,
}
#[derive(Debug, Serialize, Deserialize, Validate)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="Confirm password reset with token and new password",
example = json!({
"token": "reset_token_abc123",
"new_password": "NewSecurePassword123!"
})
))]
pub struct PasswordResetConfirm {
#[cfg_attr(feature = "openapi", schema(example = "reset_token_abc123"))]
pub token: String,
#[validate(length(min = 8))]
#[cfg_attr(feature = "openapi", schema(example = "NewSecurePassword123!", min_length = 8))]
pub new_password: String,
}
#[derive(Debug, Serialize, Deserialize, Validate)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="New user registration request",
example = json!({
"email": "newuser@example.com",
"password": "SecurePassword123!",
"first_name": "John",
"last_name": "Doe",
"account_id": "507f1f77bcf86cd799439011"
})
))]
pub struct RegisterRequest {
#[validate(email)]
#[cfg_attr(feature = "openapi", schema(example = "newuser@example.com", format = "email"))]
pub email: String,
#[validate(length(min = 8))]
#[cfg_attr(feature = "openapi", schema(example = "SecurePassword123!", min_length = 8))]
pub password: String,
#[cfg_attr(feature = "openapi", schema(example = "John"))]
pub first_name: String,
#[cfg_attr(feature = "openapi", schema(example = "Doe"))]
pub last_name: String,
#[cfg_attr(feature = "openapi", schema(example = "507f1f77bcf86cd799439011"))]
pub account_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "openapi", schema(
title ="Response after user registration attempt",
example = json!({
"success": true,
"user_id": "507f1f77bcf86cd799439011",
"message": "Registration successful. Please check your email to verify your account."
})
))]
pub struct RegisterResponse {
pub success: bool,
#[cfg_attr(feature = "openapi", schema(example = "507f1f77bcf86cd799439011"))]
pub user_id: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "Registration successful"))]
pub message: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "Email already registered"))]
pub error: Option<String>,
}