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

#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "user")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
    #[sea_orm(unique)]
    pub email: String,
    #[sea_orm(has_one)]
    pub profile: HasOne<super::profile::Entity>,
    #[sea_orm(has_many)]
    pub posts: HasMany<super::post::Entity>,
    #[sea_orm(self_ref, via = "user_follower", from = "User", to = "Follower")]
    pub followers: HasMany<Entity>,
    #[sea_orm(self_ref, via = "user_follower", reverse)]
    pub following: HasMany<Entity>,
}

impl ActiveModelBehavior for ActiveModel {}

pub use super::user_follower::Entity as Follower;
// the name `EntityReverse` is still subject to change
pub use super::user_follower::EntityReverse as Following;

// the following trait impl will be generated by the marco:
// impl RelatedSelfVia<super::user_follower::Entity> for Entity {
//     fn to() -> RelationDef {
//         super::user_follower::Relation::Follower.def()
//     }
//     fn via() -> RelationDef {
//         super::user_follower::Relation::User.def().rev()
//     }
// }
