//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0

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

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "user")]
#[sea_orm::model]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    #[sea_orm(unique)]
    pub username: String,
    #[serde(skip_serializing)]
    pub password_hash: String,
    pub avatar: Option<String>,
    pub timezone: String,
    pub bark_url: Option<String>,
    pub inapp_enabled: bool,
    pub bark_enabled: bool,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    pub invite_id: Option<Uuid>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::invite::Entity",
        from = "Column::InviteId",
        to = "super::invite::Column::Id",
        on_update = "Cascade",
        on_delete = "SetNull"
    )]
    Invite,
    #[sea_orm(has_many = "super::notification::Entity")]
    Notification,
    #[sea_orm(has_many = "super::reminder_task::Entity")]
    ReminderTask,
    #[sea_orm(has_many = "super::reminder_task_recipient::Entity")]
    ReminderTaskRecipient,
    #[sea_orm(has_many = "super::todo::Entity")]
    Todo,
}

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

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

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

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

impl Related<super::reminder_task::Entity> for Entity {
    fn to() -> RelationDef {
        super::reminder_task_recipient::Relation::ReminderTask.def()
    }
    fn via() -> Option<RelationDef> {
        Some(super::reminder_task_recipient::Relation::User.def().rev())
    }
}

impl ActiveModelBehavior for ActiveModel {}
