package models

import (
	"time"

	"gorm.io/gorm"
)

// PlaylistShareLink représente un lien de partage public pour une playlist
// T0488: Create Playlist Public Share Link
type PlaylistShareLink struct {
	ID          int64          `gorm:"primaryKey;autoIncrement" json:"id" db:"id"`
	PlaylistID  int64          `gorm:"not null;index:idx_playlist_share_links_playlist_id" json:"playlist_id" db:"playlist_id"`
	UserID      int64          `gorm:"not null;index:idx_playlist_share_links_user_id" json:"user_id" db:"user_id"`
	ShareToken  string         `gorm:"uniqueIndex;not null;size:255" json:"share_token" db:"share_token"`
	ExpiresAt   *time.Time     `json:"expires_at,omitempty" db:"expires_at"`
	AccessCount int64          `gorm:"default:0" json:"access_count" db:"access_count"`
	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 `gorm:"index" json:"-" db:"deleted_at"`

	// Relations
	Playlist Playlist `gorm:"foreignKey:PlaylistID;constraint:OnDelete:CASCADE" json:"-"`
	User     User     `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"`
}

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

