package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) // LiveStream represents a live stream metadata record type LiveStream struct { ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id" db:"id"` UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id" db:"user_id"` Title string `gorm:"size:200;not null" json:"title" db:"title"` Description string `gorm:"type:text" json:"description" db:"description"` Category string `gorm:"size:100" json:"category" db:"category"` ThumbnailURL string `gorm:"size:500" json:"thumbnailUrl" db:"thumbnail_url"` StreamKey string `gorm:"size:100" json:"-" db:"stream_key"` StreamerName string `gorm:"size:100" json:"streamer" db:"streamer_name"` IsLive bool `gorm:"default:false" json:"isLive" db:"is_live"` StartedAt *time.Time `json:"startedAt" db:"started_at"` EndedAt *time.Time `json:"endedAt" db:"ended_at"` ViewerCount int `gorm:"default:0" json:"viewers" db:"viewer_count"` Tags []string `gorm:"serializer:json;default:'[]'" json:"tags" db:"tags"` ScheduledAt *time.Time `json:"scheduled_at,omitempty" db:"scheduled_at"` StreamURL string `gorm:"type:text;default:''" json:"stream_url,omitempty" db:"stream_url"` IsVOD bool `gorm:"default:false" json:"is_vod" db:"is_vod"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" db:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" db:"updated_at"` DeletedAt gorm.DeletedAt `json:"-" db:"deleted_at"` User *User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"` } // TableName defines the table name for GORM func (LiveStream) TableName() string { return "live_streams" } // BeforeCreate hook for GORM to generate UUID func (m *LiveStream) BeforeCreate(tx *gorm.DB) error { if m.ID == uuid.Nil { m.ID = uuid.New() } return nil }