package account import ( "time" "github.com/google/uuid" ) // User - Пользователь системы (Telegram аккаунт) type User struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` TelegramID int64 `gorm:"uniqueIndex;not null" json:"telegram_id"` Username string `gorm:"type:varchar(100)" json:"username"` FirstName string `gorm:"type:varchar(100)" json:"first_name"` LastName string `gorm:"type:varchar(100)" json:"last_name"` PhotoURL string `gorm:"type:text" json:"photo_url"` IsAdmin bool `gorm:"default:false" json:"is_admin"` // Связь с серверами Servers []RMSServer `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"servers,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // RMSServer - Настройки подключения к iikoRMS type RMSServer struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"` Name string `gorm:"type:varchar(100);not null" json:"name"` // Название (напр. "Ресторан на Ленина") // Credentials BaseURL string `gorm:"type:varchar(255);not null" json:"base_url"` Login string `gorm:"type:varchar(100);not null" json:"login"` EncryptedPassword string `gorm:"type:text;not null" json:"-"` // Пароль храним зашифрованным DefaultStoreID *uuid.UUID `gorm:"type:uuid" json:"default_store_id"` // Склад для подстановки RootGroupGUID *uuid.UUID `gorm:"type:uuid" json:"root_group_guid"` // ID корневой папки для поиска товаров AutoProcess bool `gorm:"default:false" json:"auto_process"` // Пытаться сразу проводить накладную // Billing / Stats InvoiceCount int `gorm:"default:0" json:"invoice_count"` // Счетчик успешно отправленных накладных IsActive bool `gorm:"default:true" json:"is_active"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // Repository интерфейс управления аккаунтами type Repository interface { // Users GetOrCreateUser(telegramID int64, username, first, last string) (*User, error) GetUserByTelegramID(telegramID int64) (*User, error) // Servers SaveServer(server *RMSServer) error SetActiveServer(userID, serverID uuid.UUID) error GetActiveServer(userID uuid.UUID) (*RMSServer, error) // Получить активный (первый попавшийся или помеченный) GetAllServers(userID uuid.UUID) ([]RMSServer, error) DeleteServer(serverID uuid.UUID) error // Billing IncrementInvoiceCount(serverID uuid.UUID) error }