use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::common::{UserInfo, RoomInfo};

/// Created when a user publishes an article in an article channel.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleCreatedService {
    pub article: ArticleItem,
    pub channel: RoomInfo,
    pub author: UserInfo,
}

/// Created when an article is updated.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleUpdatedService {
    pub article: ArticleItem,
    pub channel: RoomInfo,
}

/// Created when an article is deleted (soft-delete).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleDeletedService {
    pub article_id: Uuid,
    pub channel: RoomInfo,
    pub deleted_by: UserInfo,
}

/// Lightweight article card for waterfall feed listing.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleItem {
    pub id: Uuid,
    pub channel: Uuid,
    pub author: UserInfo,
    pub title: String,
    pub cover_url: Option<String>,
    pub summary: Option<String>,
    pub tags: Vec<String>,
    pub like_count: i64,
    pub comment_count: i64,
    pub view_count: i64,
    pub is_pinned: bool,
    pub content_type: String,
    pub status: String,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

/// Full article with content body.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleDetail {
    #[serde(flatten)]
    pub card: ArticleItem,
    pub content: String,
}

/// Paginated article list response.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleListService {
    pub articles: Vec<ArticleItem>,
    pub total: i64,
    pub has_more: bool,
}

/// Fired when a user likes an article.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleLikedService {
    pub article_id: Uuid,
    pub channel: RoomInfo,
    pub user: UserInfo,
    pub like_count: i64,
}

/// Fired when a user unlikes an article.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleUnlikedService {
    pub article_id: Uuid,
    pub channel: RoomInfo,
    pub user: UserInfo,
    pub like_count: i64,
}

/// Created when a comment is posted on an article.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleCommentCreatedService {
    pub comment: model::channel::ArticleCommentItem,
    pub channel: RoomInfo,
    pub author: UserInfo,
    pub comment_count: i64,
}

/// Paginated comment list.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleCommentListService {
    pub comments: Vec<model::channel::ArticleCommentItem>,
    pub total: i64,
}

/// Fired when a comment is deleted.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleCommentDeletedService {
    pub comment_id: Uuid,
    pub article_id: Uuid,
    pub channel: RoomInfo,
    pub deleted_by: UserInfo,
    pub comment_count: i64,
}

/// List of users who liked an article.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArticleLikedUsersService {
    pub article_id: Uuid,
    pub users: Vec<UserInfo>,
    pub total: i64,
}
