//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3

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

use crate::session_trait::UserSession;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "session")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub candidate_id: i32,
    pub ip_address: String,
    pub created_at: DateTime,
    pub expires_at: DateTime,
    pub updated_at: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::application::Entity",
        from = "Column::CandidateId",
        to = "super::application::Column::Id",
        on_update = "Cascade",
        on_delete = "Cascade"
    )]
    Application,
}

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

impl ActiveModelBehavior for ActiveModel {}

#[async_trait::async_trait]
impl UserSession for Model {
    async fn id(&self) -> Uuid {
        self.id
    }
    async fn expires_at(&self) -> chrono::NaiveDateTime {
        self.expires_at
    }
}