package models

import (
	"time"
)

// PlaylistVersionAction représente le type d'action effectuée sur une playlist
type PlaylistVersionAction string

const (
	PlaylistVersionActionCreated  PlaylistVersionAction = "created"
	PlaylistVersionActionUpdated  PlaylistVersionAction = "updated"
	PlaylistVersionActionRestored PlaylistVersionAction = "restored"
)

// PlaylistVersion représente une version d'une playlist
// T0509: Create Playlist Version History
type PlaylistVersion struct {
	ID          int64                 `gorm:"primaryKey;autoIncrement" json:"id" db:"id"`
	PlaylistID  int64                 `gorm:"not null;index:idx_playlist_versions_playlist_id" json:"playlist_id" db:"playlist_id"`
	UserID      int64                 `gorm:"not null;index:idx_playlist_versions_user_id" json:"user_id" db:"user_id"`
	Version     int                   `gorm:"not null" json:"version" db:"version"`
	Action      PlaylistVersionAction `gorm:"not null;size:50;index:idx_playlist_versions_action" json:"action" db:"action"`
	Title       string                `gorm:"size:200" json:"title" db:"title"`
	Description string                `gorm:"type:text" json:"description,omitempty" db:"description"`
	IsPublic    bool                  `gorm:"default:true" json:"is_public" db:"is_public"`
	CoverURL    string                `gorm:"size:500" json:"cover_url,omitempty" db:"cover_url"`
	// Snapshot des tracks au moment de la version (JSON)
	TracksSnapshot string    `gorm:"type:text" json:"tracks_snapshot,omitempty" db:"tracks_snapshot"`
	CreatedAt      time.Time `gorm:"autoCreateTime;index:idx_playlist_versions_created_at" json:"created_at" db:"created_at"`

	// Relations
	Playlist *Playlist `gorm:"foreignKey:PlaylistID;constraint:OnDelete:CASCADE" json:"playlist,omitempty"`
	User     *User     `gorm:"foreignKey:UserID;constraint:OnDelete:SET NULL" json:"user,omitempty"`
}

// TableName définit le nom de la table pour GORM
func (PlaylistVersion) TableName() string {
	return "playlist_versions"
}

