package domain

import (
	"time"

	"github.com/gocql/gocql"
	"github.com/google/uuid"
)

// Session represents a user's authentication session
type Session struct {
	ID        string    `json:"id"`         // Session UUID
	UserID    uint64    `json:"user_id"`    // User's ID
	UserUUID  uuid.UUID `json:"user_uuid"`  // User's UUID
	UserEmail string    `json:"user_email"` // User's email
	UserName  string    `json:"user_name"`  // User's full name
	UserRole  string    `json:"user_role"`  // User's role (admin, user, etc.)
	TenantID  uuid.UUID `json:"tenant_id"`  // Tenant ID for multi-tenancy
	CreatedAt time.Time `json:"created_at"` // When the session was created
	ExpiresAt time.Time `json:"expires_at"` // When the session expires
}

// NewSession creates a new session
func NewSession(userID uint64, userUUID uuid.UUID, userEmail, userName, userRole string, tenantID uuid.UUID, duration time.Duration) *Session {
	now := time.Now()
	return &Session{
		ID:        gocql.TimeUUID().String(),
		UserID:    userID,
		UserUUID:  userUUID,
		UserEmail: userEmail,
		UserName:  userName,
		UserRole:  userRole,
		TenantID:  tenantID,
		CreatedAt: now,
		ExpiresAt: now.Add(duration),
	}
}

// IsExpired checks if the session has expired
func (s *Session) IsExpired() bool {
	return time.Now().After(s.ExpiresAt)
}
