package entities import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type TokenType string const ( TokenTypeSpin TokenType = "SPIN" TokenTypeRaffle TokenType = "RAFFLE" TokenTypeMinigame TokenType = "MINIGAME" ) type CustomerTokens struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` CustomerID uuid.UUID `gorm:"type:uuid;not null;index" json:"customer_id" validate:"required"` TokenType TokenType `gorm:"type:varchar(50);not null" json:"token_type" validate:"required,oneof=SPIN RAFFLE MINIGAME"` Balance int64 `gorm:"not null;default:0" json:"balance" validate:"min=0"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` Customer Customer `gorm:"foreignKey:CustomerID" json:"customer,omitempty"` } func (ct *CustomerTokens) BeforeCreate(tx *gorm.DB) error { if ct.ID == uuid.Nil { ct.ID = uuid.New() } return nil } func (CustomerTokens) TableName() string { return "customer_tokens" }