//! Entity representing a following relationship.
//!
//! Tracks which local actors follow which remote actors. The follow_activity_id
//! is the ActivityPub Follow activity's id we sent, used for matching Accept/Reject.

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

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "ap_following")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    pub local_actor_id: i64,
    pub remote_actor_id: i64,
    #[sea_orm(unique)]
    pub follow_activity_id: String,
    pub state: String,
    pub created_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::ap_actors::Entity",
        from = "Column::LocalActorId",
        to = "super::ap_actors::Column::Id"
    )]
    ApActors,
    #[sea_orm(
        belongs_to = "super::ap_remote_actors::Entity",
        from = "Column::RemoteActorId",
        to = "super::ap_remote_actors::Column::Id"
    )]
    ApRemoteActors,
}

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

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

impl ActiveModelBehavior for ActiveModel {}
