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

use super::ReactionType;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "issue_comment_reaction")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub comment: i64,
    #[sea_orm(primary_key, column_name = "user_uuid")]
    pub user: UserId,
    #[sea_orm(primary_key)]
    pub reaction: String,
    pub created_at: DateTimeUtc,
}

impl Model {
    pub fn reaction_enum(&self) -> Result<ReactionType, &'static str> {
        self.reaction.parse()
    }
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
