use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct AuditLogRequest {
    #[serde(default)]
    pub from: Option<String>,
    #[serde(default)]
    pub to: Option<String>,
    #[serde(default)]
    pub event_type: Option<String>,
    #[serde(default)]
    pub user_id: Option<i32>,
    #[serde(default = "default_limit")]
    pub limit: i64,
}

fn default_limit() -> i64 {
    100
}

#[derive(Debug, Clone, Serialize)]
pub struct SessionAuditLog {
    pub id: i32,
    pub user_id: i32,
    pub username: Option<String>,
    pub session_id: Option<String>,
    pub event: String,
    pub ip_address: Option<String>,
    pub user_agent: Option<String>,
    pub metadata: serde_json::Value,
    pub timestamp: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize)]
pub struct SyncAuditLog {
    pub id: i32,
    pub sync_job_id: i32,
    pub entity_type: String,
    pub entity_id: String,
    pub action: String,
    pub status: String,
    pub error_message: Option<String>,
    pub metadata: serde_json::Value,
    pub timestamp: DateTime<Utc>,
    pub resolution_status: Option<String>,
}

#[derive(Debug, Serialize)]
pub struct AuditSummary {
    pub total_events: i64,
    pub login_events: i64,
    pub logout_events: i64,
    pub sync_events: i64,
    pub error_events: i64,
}
