package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) // QueueSession represents a shared collaborative queue (v0.203 Lot D1) type QueueSession struct { ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"` ShareToken string `gorm:"type:varchar(32);uniqueIndex;not null" json:"share_token"` CreatorID uuid.UUID `gorm:"type:uuid;not null;index" json:"creator_id"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` Creator User `gorm:"foreignKey:CreatorID" json:"-"` Items []SharedQueueItem `gorm:"foreignKey:SessionID;constraint:OnDelete:CASCADE" json:"items,omitempty"` } // TableName defines the table name for GORM func (QueueSession) TableName() string { return "queue_sessions" } // BeforeCreate GORM hook to generate UUID if not set func (qs *QueueSession) BeforeCreate(tx *gorm.DB) error { if qs.ID == uuid.Nil { qs.ID = uuid.New() } return nil } // SharedQueueItem represents a track in a shared queue session type SharedQueueItem struct { ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"` SessionID uuid.UUID `gorm:"type:uuid;not null;index" json:"session_id"` TrackID uuid.UUID `gorm:"type:uuid;not null" json:"track_id"` Position int `gorm:"not null" json:"position"` AddedAt time.Time `gorm:"autoCreateTime" json:"added_at"` Track Track `gorm:"foreignKey:TrackID" json:"track,omitempty"` } // TableName defines the table name for GORM func (SharedQueueItem) TableName() string { return "shared_queue_items" } // BeforeCreate GORM hook to generate UUID if not set func (qi *SharedQueueItem) BeforeCreate(tx *gorm.DB) error { if qi.ID == uuid.Nil { qi.ID = uuid.New() } return nil }