package port

import (
	"context"

	"git.threesix.ai/jordan/persona-community-5/services/persona-api/internal/domain"
)

// SessionRepository defines the interface for session persistence.
type SessionRepository interface {
	// Create persists a new session record.
	Create(ctx context.Context, session *domain.Session) error

	// Get returns a session by ID. Returns domain.ErrSessionNotFound if not found.
	Get(ctx context.Context, id domain.SessionID) (*domain.Session, error)

	// ListByUser returns all active (non-revoked) sessions for a user.
	ListByUser(ctx context.Context, userID domain.UserID) ([]domain.Session, error)

	// UpdateLastActive updates the last_active_at timestamp for a session.
	UpdateLastActive(ctx context.Context, id domain.SessionID) error

	// Revoke marks a session as revoked by setting revoked_at.
	Revoke(ctx context.Context, id domain.SessionID) error

	// RevokeAllForUser revokes all sessions for a user.
	// If exceptID is non-nil, that session is kept active.
	RevokeAllForUser(ctx context.Context, userID domain.UserID, exceptID *domain.SessionID) error

	// DeleteExpired removes sessions that have passed their expiry time.
	// Returns the number of sessions deleted.
	DeleteExpired(ctx context.Context) (int, error)
}
