1use serde::{Deserialize, Serialize};
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6use validator::Validate;
7
8#[derive(Debug, Serialize, Deserialize, Validate)]
10#[cfg_attr(feature = "openapi", derive(ToSchema))]
11#[cfg_attr(feature = "openapi", schema(
12 title ="Authentication request with email and password",
13 example = json!({
14 "email": "user@example.com",
15 "password": "SecurePassword123!"
16 })
17))]
18pub struct LoginRequest {
19 #[validate(email)]
21 #[cfg_attr(feature = "openapi", schema(example = "user@example.com", format = "email"))]
22 pub email: String,
23
24 #[validate(length(min = 1))]
26 #[cfg_attr(feature = "openapi", schema(example = "SecurePassword123!", min_length = 1))]
27 pub password: String,
28}
29
30#[derive(Debug, Serialize, Deserialize)]
32#[cfg_attr(feature = "openapi", derive(ToSchema))]
33#[cfg_attr(feature = "openapi", schema(
34 title ="Login response containing authentication token and user information",
35 example = json!({
36 "success": true,
37 "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
38 "user_id": "507f1f77bcf86cd799439011",
39 "agent_id": "agent_123",
40 "permissions": ["read:contacts", "write:contacts", "admin:account"],
41 "softphone_enabled": true
42 })
43))]
44pub struct LoginResponse {
45 pub success: bool,
47
48 #[cfg_attr(feature = "openapi", schema(example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."))]
50 pub token: Option<String>,
51
52 #[cfg_attr(feature = "openapi", schema(example = "507f1f77bcf86cd799439011"))]
54 pub user_id: Option<String>,
55
56 #[cfg_attr(feature = "openapi", schema(example = "agent_123"))]
58 pub agent_id: Option<String>,
59
60 #[cfg_attr(feature = "openapi", schema(example = json!(["read:contacts", "write:contacts"])))]
62 pub permissions: Option<Vec<String>>,
63
64 #[cfg_attr(feature = "openapi", schema(example = "Invalid credentials"))]
66 pub error: Option<String>,
67
68 #[cfg_attr(feature = "openapi", schema(example = true))]
70 pub softphone_enabled: Option<bool>,
71}
72
73#[derive(Debug, Serialize, Deserialize)]
75#[cfg_attr(feature = "openapi", derive(ToSchema))]
76#[cfg_attr(feature = "openapi", schema(
77 title ="Logout request with token or session ID"
78))]
79pub struct LogoutRequest {
80 #[cfg_attr(feature = "openapi", schema(example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."))]
82 pub token: Option<String>,
83
84 #[cfg_attr(feature = "openapi", schema(example = "sess_1234567890"))]
86 pub session_id: Option<String>,
87}
88
89#[derive(Debug, Serialize, Deserialize, Validate)]
91#[cfg_attr(feature = "openapi", derive(ToSchema))]
92#[cfg_attr(feature = "openapi", schema(
93 title ="Request to initiate password reset process",
94 example = json!({
95 "email": "user@example.com"
96 })
97))]
98pub struct PasswordResetRequest {
99 #[validate(email)]
101 #[cfg_attr(feature = "openapi", schema(example = "user@example.com", format = "email"))]
102 pub email: String,
103}
104
105#[derive(Debug, Serialize, Deserialize, Validate)]
107#[cfg_attr(feature = "openapi", derive(ToSchema))]
108#[cfg_attr(feature = "openapi", schema(
109 title ="Confirm password reset with token and new password",
110 example = json!({
111 "token": "reset_token_abc123",
112 "new_password": "NewSecurePassword123!"
113 })
114))]
115pub struct PasswordResetConfirm {
116 #[cfg_attr(feature = "openapi", schema(example = "reset_token_abc123"))]
118 pub token: String,
119
120 #[validate(length(min = 8))]
122 #[cfg_attr(feature = "openapi", schema(example = "NewSecurePassword123!", min_length = 8))]
123 pub new_password: String,
124}
125
126#[derive(Debug, Serialize, Deserialize, Validate)]
128#[cfg_attr(feature = "openapi", derive(ToSchema))]
129#[cfg_attr(feature = "openapi", schema(
130 title ="New user registration request",
131 example = json!({
132 "email": "newuser@example.com",
133 "password": "SecurePassword123!",
134 "first_name": "John",
135 "last_name": "Doe",
136 "account_id": "507f1f77bcf86cd799439011"
137 })
138))]
139pub struct RegisterRequest {
140 #[validate(email)]
142 #[cfg_attr(feature = "openapi", schema(example = "newuser@example.com", format = "email"))]
143 pub email: String,
144
145 #[validate(length(min = 8))]
147 #[cfg_attr(feature = "openapi", schema(example = "SecurePassword123!", min_length = 8))]
148 pub password: String,
149
150 #[cfg_attr(feature = "openapi", schema(example = "John"))]
152 pub first_name: String,
153
154 #[cfg_attr(feature = "openapi", schema(example = "Doe"))]
156 pub last_name: String,
157
158 #[cfg_attr(feature = "openapi", schema(example = "507f1f77bcf86cd799439011"))]
160 pub account_id: Option<String>,
161}
162
163#[derive(Debug, Serialize, Deserialize)]
165#[cfg_attr(feature = "openapi", derive(ToSchema))]
166#[cfg_attr(feature = "openapi", schema(
167 title ="Response after user registration attempt",
168 example = json!({
169 "success": true,
170 "user_id": "507f1f77bcf86cd799439011",
171 "message": "Registration successful. Please check your email to verify your account."
172 })
173))]
174pub struct RegisterResponse {
175 pub success: bool,
177
178 #[cfg_attr(feature = "openapi", schema(example = "507f1f77bcf86cd799439011"))]
180 pub user_id: Option<String>,
181
182 #[cfg_attr(feature = "openapi", schema(example = "Registration successful"))]
184 pub message: Option<String>,
185
186 #[cfg_attr(feature = "openapi", schema(example = "Email already registered"))]
188 pub error: Option<String>,
189}