use crate::{DateTimeUtc, MessageId, UserId};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "room_message_edit_history")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: Uuid,
    pub message: MessageId,
    pub user: UserId,
    /// Previous content before edit
    pub old_content: String,
    /// New content after edit
    pub new_content: String,
    pub edited_at: DateTimeUtc,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::room_message::Entity",
        from = "Column::Message",
        to = "super::room_message::Column::Id"
    )]
    Message,
}

impl Related<super::room_message::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Message.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}
