package output

import (
	"context"
	"time"

	"github.com/google/uuid"
	"github.com/rwadurian/mpc-system/services/session-coordinator/domain/entities"
	"github.com/rwadurian/mpc-system/services/session-coordinator/domain/value_objects"
)

// SessionStoragePort defines the output port for session storage
// This is the interface that infrastructure adapters must implement
type SessionStoragePort interface {
	// Session operations
	SaveSession(ctx context.Context, session *entities.MPCSession) error
	GetSession(ctx context.Context, id uuid.UUID) (*entities.MPCSession, error)
	UpdateSession(ctx context.Context, session *entities.MPCSession) error
	DeleteSession(ctx context.Context, id uuid.UUID) error

	// Query operations
	GetSessionsByStatus(ctx context.Context, status value_objects.SessionStatus) ([]*entities.MPCSession, error)
	GetExpiredSessions(ctx context.Context) ([]*entities.MPCSession, error)
	GetSessionsByCreator(ctx context.Context, creatorID string, limit, offset int) ([]*entities.MPCSession, error)
}

// SessionCachePort defines the output port for session caching
type SessionCachePort interface {
	// Cache operations
	CacheSession(ctx context.Context, session *entities.MPCSession, ttl time.Duration) error
	GetCachedSession(ctx context.Context, id uuid.UUID) (*entities.MPCSession, error)
	InvalidateSession(ctx context.Context, id uuid.UUID) error

	// Distributed lock for session operations
	AcquireLock(ctx context.Context, sessionID uuid.UUID, ttl time.Duration) (bool, error)
	ReleaseLock(ctx context.Context, sessionID uuid.UUID) error

	// Online status tracking
	SetPartyOnline(ctx context.Context, sessionID uuid.UUID, partyID string, ttl time.Duration) error
	IsPartyOnline(ctx context.Context, sessionID uuid.UUID, partyID string) (bool, error)
	GetOnlineParties(ctx context.Context, sessionID uuid.UUID) ([]string, error)
}
