use std::collections::HashMap;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OAuthAuditEvent {
pub event_type: String,
pub provider: String,
pub user_id: Option<String>,
pub status: String,
pub error: Option<String>,
pub timestamp: DateTime<Utc>,
pub metadata: HashMap<String, String>,
}
impl OAuthAuditEvent {
pub fn new(
event_type: impl Into<String>,
provider: impl Into<String>,
status: impl Into<String>,
) -> Self {
Self {
event_type: event_type.into(),
provider: provider.into(),
user_id: None,
status: status.into(),
error: None,
timestamp: Utc::now(),
metadata: HashMap::new(),
}
}
#[must_use]
pub fn with_user_id(mut self, user_id: String) -> Self {
self.user_id = Some(user_id);
self
}
#[must_use]
pub fn with_error(mut self, error: String) -> Self {
self.error = Some(error);
self
}
#[must_use]
pub fn with_metadata(mut self, key: String, value: String) -> Self {
self.metadata.insert(key, value);
self
}
}