package models

import (
	"time"

	"gorm.io/gorm"
)

// PlaylistFollow représente un follow d'un utilisateur sur une playlist
// T0489: Create Playlist Follow Feature
type PlaylistFollow struct {
	ID         int64          `gorm:"primaryKey;autoIncrement" json:"id" db:"id"`
	PlaylistID int64          `gorm:"not null;index:idx_playlist_follows_playlist_id" json:"playlist_id" db:"playlist_id"`
	UserID     int64          `gorm:"not null;index:idx_playlist_follows_user_id" json:"user_id" db:"user_id"`
	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:"user,omitempty"`
}

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

