use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "ap_reactions")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    pub note_id: Option<i64>,
    pub remote_note_id: Option<i64>,
    pub remote_note_object_url: Option<String>,
    pub kind: String,
    pub emoji: Option<String>,
    pub remote_actor_id: Option<i64>,
    pub local_user_id: Option<i64>,
    pub activity_id: Option<String>,
    pub created_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::ap_notes::Entity",
        from = "Column::NoteId",
        to = "super::ap_notes::Column::Id"
    )]
    ApNotes,
    #[sea_orm(
        belongs_to = "super::ap_remote_notes::Entity",
        from = "Column::RemoteNoteId",
        to = "super::ap_remote_notes::Column::Id"
    )]
    ApRemoteNotes,
    #[sea_orm(
        belongs_to = "super::ap_remote_actors::Entity",
        from = "Column::RemoteActorId",
        to = "super::ap_remote_actors::Column::Id"
    )]
    ApRemoteActors,
    #[sea_orm(
        belongs_to = "super::users::Entity",
        from = "Column::LocalUserId",
        to = "super::users::Column::Id"
    )]
    Users,
}

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

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

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

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

impl ActiveModelBehavior for ActiveModel {}
