//! User password types for the Salesforce REST API.

use serde::{Deserialize, Serialize};

/// Status of a user's password.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct UserPasswordStatus {
    #[serde(rename = "isExpired")]
    pub is_expired: bool,
}

/// Request to set a user's password.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SetPasswordRequest {
    #[serde(rename = "NewPassword")]
    pub new_password: String,
}

/// Response from resetting a user's password.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SetPasswordResponse {
    #[serde(rename = "NewPassword")]
    pub new_password: String,
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::json;

    #[test]
    fn test_user_password_status_deserialize() {
        let json = json!({"isExpired": false});
        let status: UserPasswordStatus = serde_json::from_value(json).unwrap();
        assert!(!status.is_expired);
    }

    #[test]
    fn test_user_password_status_expired() {
        let json = json!({"isExpired": true});
        let status: UserPasswordStatus = serde_json::from_value(json).unwrap();
        assert!(status.is_expired);
    }

    #[test]
    fn test_set_password_request_serialize() {
        let request = SetPasswordRequest {
            new_password: "NewPass123!".to_string(),
        };
        let json = serde_json::to_value(&request).unwrap();
        assert_eq!(json["NewPassword"], "NewPass123!");
    }

    #[test]
    fn test_set_password_response_deserialize() {
        let json = json!({"NewPassword": "AutoGenerated123!"});
        let response: SetPasswordResponse = serde_json::from_value(json).unwrap();
        assert_eq!(response.new_password, "AutoGenerated123!");
    }
}
