package models import "time" // CategoryKey شناسه‌ی ثابت هر دسته‌ی لیست انتخابی. // این کلیدها توی کد استفاده می‌شن (برای هر مرحله از آنبوردینگ) // ولی گزینه‌های داخل هر دسته کاملاً از پنل ادمین قابل مدیریت هستن. type CategoryKey string const ( CategoryEducationLevel CategoryKey = "education_level" CategoryFieldOfStudy CategoryKey = "field_of_study" CategoryOccupation CategoryKey = "occupation" CategoryImportantInRelationship CategoryKey = "important_in_relationship" CategoryInterest CategoryKey = "interest" CategoryLookingFor CategoryKey = "looking_for" ) // AllCategoryKeys برای seed کردن و اعتبارسنجی var AllCategoryKeys = []CategoryKey{ CategoryEducationLevel, CategoryFieldOfStudy, CategoryOccupation, CategoryImportantInRelationship, CategoryInterest, CategoryLookingFor, } // Category یک دسته‌ی لیست انتخابی (مثلاً «علاقه‌مندی‌ها»). // MinSelect/MaxSelect تعداد مجاز انتخاب رو مشخص می‌کنه (MaxSelect=0 یعنی نامحدود). type Category struct { ID uint `gorm:"primaryKey" json:"id"` Key CategoryKey `gorm:"size:50;uniqueIndex;not null" json:"key"` Title string `gorm:"size:150;not null" json:"title"` // توجه: عمداً تگ gorm:"default:..." روی این دو فیلد گذاشته نشده. // GORM مقادیر صفر (zero value) رو برای ستون‌هایی که تگ default دارن از // INSERT حذف می‌کنه (چون نمی‌تونه "صفر عمدی" رو از "ست نشده" تشخیص بده) // و این یعنی MaxSelect=0 (به‌معنی نامحدود) به‌جای ذخیره‌شدن، با دیفالت // دیتابیس جایگزین می‌شد. چون همیشه این دو مقدار رو صریح ست می‌کنیم // (در seed و در آپدیت ادمین)، نیازی به دیفالت دیتابیسی نیست. MinSelect int `gorm:"not null" json:"min_select"` MaxSelect int `gorm:"not null" json:"max_select"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Options []Option `gorm:"foreignKey:CategoryID" json:"options,omitempty"` } func (Category) TableName() string { return "categories" } // Option یک آیتم قابل‌انتخاب داخل یک دسته (مدیریت‌شده توسط ادمین) type Option struct { ID uint `gorm:"primaryKey" json:"id"` CategoryID uint `gorm:"not null;index" json:"category_id"` Title string `gorm:"size:150;not null" json:"title"` SortOrder int `gorm:"default:0;not null" json:"sort_order"` IsActive bool `gorm:"default:true;not null" json:"is_active"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (Option) TableName() string { return "options" } // UserOptionSelection انتخاب‌های کاربر از یک دسته‌ی مشخص. // برای هر مرحله (مثل علاقه‌مندی‌ها) چند ردیف از این جدول ساخته می‌شه. type UserOptionSelection struct { ID uint `gorm:"primaryKey" json:"id"` UserID uint `gorm:"not null;uniqueIndex:idx_user_category_option" json:"user_id"` CategoryID uint `gorm:"not null;uniqueIndex:idx_user_category_option;index" json:"category_id"` OptionID uint `gorm:"not null;uniqueIndex:idx_user_category_option" json:"option_id"` CreatedAt time.Time `json:"created_at"` Option *Option `gorm:"foreignKey:OptionID" json:"option,omitempty"` } func (UserOptionSelection) TableName() string { return "user_option_selections" }