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

use crate::event::{UserInfo, WorkspaceInfo};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BanEventType {
    Banned,
    Unbanned,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum BanEvent {
    #[serde(rename = "ban.banned")]
    Banned(BannedService),
    #[serde(rename = "ban.unbanned")]
    Unbanned(UnbannedService),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BannedService {
    pub workspace: WorkspaceInfo,
    pub user: UserInfo,
    pub banned_by: UserInfo,
    pub reason: Option<String>,
    pub expires_at: Option<DateTime<Utc>>,
    pub banned_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnbannedService {
    pub workspace: WorkspaceInfo,
    pub user: UserInfo,
    pub unbanned_by: UserInfo,
    pub unbanned_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BanCreateClient {
    pub workspace: WorkspaceInfo,
    pub user: UserInfo,
    pub reason: Option<String>,
    pub expires_at: Option<DateTime<Utc>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BanRemoveClient {
    pub workspace: WorkspaceInfo,
    pub user: UserInfo,
}
