//! User entity for authentication. use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "users")] pub struct Model { #[sea_orm(primary_key)] pub id: i32, #[sea_orm(unique)] pub username: String, #[sea_orm(column_type = "Text")] pub password_hash: String, /// Foreign key to roles table pub role_id: i32, /// Display name (optional, separate from username) pub name: Option, // Profile fields /// Height in centimeters pub height_cm: Option, /// Blood type (A+, B-, O+, etc.) pub blood_type: Option, /// Date of birth pub birthdate: Option, // Lifestyle / Habits /// Whether the user smokes pub smoking: Option, /// Whether the user consumes alcohol pub alcohol: Option, /// Foreign key to diet types pub diet_id: Option, /// URL to profile avatar icon pub avatar_url: Option, /// User's own Mistral API key (BYOK - Bring Your Own Key) pub mistral_api_key: Option, pub created_at: DateTime, pub updated_at: DateTime, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { #[sea_orm(has_many = "super::session::Entity")] Sessions, #[sea_orm( belongs_to = "super::role::Entity", from = "Column::RoleId", to = "super::role::Column::Id" )] Role, #[sea_orm( belongs_to = "super::diet::Entity", from = "Column::DietId", to = "super::diet::Column::Id" )] Diet, } impl Related for Entity { fn to() -> RelationDef { Relation::Sessions.def() } } impl Related for Entity { fn to() -> RelationDef { Relation::Role.def() } } impl Related for Entity { fn to() -> RelationDef { Relation::Diet.def() } } impl ActiveModelBehavior for ActiveModel {}