use crate::event::{RoomInfo, UserInfo};
use chrono::{DateTime, Utc};
use uuid::Uuid;

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AttachmentEventType {
    Uploaded,
    ThumbnailGenerated,
    Deleted,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum AttachmentEvent {
    #[serde(rename = "attachment.uploaded")]
    Uploaded(AttachmentUploadedService),
    #[serde(rename = "attachment.thumbnail_generated")]
    ThumbnailGenerated(AttachmentThumbnailService),
    #[serde(rename = "attachment.deleted")]
    Deleted(AttachmentDeletedService),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttachmentUploadedService {
    pub id: Uuid,
    pub room: RoomInfo,
    pub message: Uuid,
    pub filename: String,
    pub content_type: Option<String>,
    pub size: i64,
    pub url: Option<String>,
    pub uploaded_by: Uuid,
    pub uploaded_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttachmentThumbnailService {
    pub id: Uuid,
    pub room: RoomInfo,
    pub thumbnail_url: String,
    pub width: i32,
    pub height: i32,
    pub generated_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttachmentDeletedService {
    pub id: Uuid,
    pub room: RoomInfo,
    pub deleted_by: UserInfo,
    pub deleted_at: DateTime<Utc>,
}
