package models

import (
	"time"
	"gorm.io/gorm"
	"github.com/google/uuid"
)

// Session represents a user session
type Session struct {
	ID        int64     `gorm:"primaryKey;autoIncrement" json:"id"`
	UserID    int64     `gorm:"not null;index" json:"user_id"`
	Token     string    `gorm:"uniqueIndex;not null" json:"-"`
	IPAddress string    `json:"ip_address"`
	UserAgent string    `json:"user_agent"`
	IsActive  bool      `gorm:"default:true" json:"is_active"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

	// Relations
	User User `gorm:"foreignKey:UserID" json:"-"`
}

// BeforeCreate hook (commented out)
// func (s *Session) BeforeCreate(tx *gorm.DB) error {
// 	if s.ID == uuid.Nil {
// 		s.ID = uuid.New()
// 	}
// 	return nil
// }

// TableName returns the table name for the Session model
func (Session) TableName() string {
	return "sessions"
}

