package models

import "time"

// BitrateAdaptationReason représente la raison de l'adaptation de bitrate
// T0346: Create Bitrate Adaptation Database Model
type BitrateAdaptationReason string

const (
	BitrateReasonNetworkSlow  BitrateAdaptationReason = "network_slow"
	BitrateReasonNetworkFast  BitrateAdaptationReason = "network_fast"
	BitrateReasonUserSelected BitrateAdaptationReason = "user_selected"
	BitrateReasonBufferLow    BitrateAdaptationReason = "buffer_low"
)

// BitrateAdaptationLog représente un log d'adaptation de bitrate
// T0346: Create Bitrate Adaptation Database Model
type BitrateAdaptationLog struct {
	ID              int64                   `gorm:"primaryKey;autoIncrement" json:"id"`
	TrackID         int64                   `gorm:"not null;index:idx_bitrate_adaptation_track_id" json:"track_id"`
	Track           Track                   `gorm:"foreignKey:TrackID;constraint:OnDelete:CASCADE" json:"track,omitempty"`
	UserID          int64                   `gorm:"not null;index:idx_bitrate_adaptation_user_id" json:"user_id"`
	User            User                    `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
	OldBitrate      int                     `gorm:"not null" json:"old_bitrate"`
	NewBitrate      int                     `gorm:"not null" json:"new_bitrate"`
	Reason          BitrateAdaptationReason `gorm:"type:varchar(50);not null" json:"reason"`
	NetworkBandwidth *int                   `gorm:"type:integer" json:"network_bandwidth,omitempty"`
	CreatedAt       time.Time               `gorm:"autoCreateTime;index:idx_bitrate_adaptation_created_at" json:"created_at"`
}

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

