package presence

import (
	"time"
)

// Status represents user presence status
type Status int

const (
	StatusOffline Status = iota
	StatusOnline
	StatusIdle
	StatusDoNotDisturb
	StatusAway
)

// Session represents a user session
type Session struct {
	UserID               string
	SessionID            string
	Status               Status
	CurrentChannelID     string
	IsMicrophoneMuted    bool
	IsSpeakerMuted       bool
	ClientVersion        string
	Platform             string
	ConnectedAt          time.Time
	LastActivityAt       time.Time
}

// NewSession creates a new session
func NewSession(userID string, sessionID string) *Session {
	now := time.Now()
	return &Session{
		UserID:         userID,
		SessionID:      sessionID,
		Status:         StatusOnline,
		ConnectedAt:    now,
		LastActivityAt: now,
	}
}

// IsIdle checks if user has been idle for longer than duration
func (s *Session) IsIdle(idleDuration time.Duration) bool {
	return time.Since(s.LastActivityAt) > idleDuration
}

// UpdateActivity updates the last activity time
func (s *Session) UpdateActivity() {
	s.LastActivityAt = time.Now()
	if s.Status == StatusIdle {
		s.Status = StatusOnline
	}
}

// MarkIdle marks the session as idle
func (s *Session) MarkIdle() {
	if s.Status == StatusOnline {
		s.Status = StatusIdle
	}
}
