package repositories

import (
	"context"
	"time"

	"github.com/google/uuid"
	"github.com/rwadurian/mpc-system/services/message-router/domain/entities"
)

// MessageRepository defines the interface for message persistence
type MessageRepository interface {
	// Save persists a new message
	Save(ctx context.Context, msg *entities.MPCMessage) error

	// GetByID retrieves a message by ID
	GetByID(ctx context.Context, id uuid.UUID) (*entities.MPCMessage, error)

	// GetPendingMessages retrieves pending messages for a party
	GetPendingMessages(ctx context.Context, sessionID uuid.UUID, partyID string, afterTime time.Time) ([]*entities.MPCMessage, error)

	// CountPendingByParty counts all pending messages for a party across all sessions
	CountPendingByParty(ctx context.Context, partyID string) (int64, error)

	// GetMessagesByRound retrieves messages for a specific round
	GetMessagesByRound(ctx context.Context, sessionID uuid.UUID, roundNumber int) ([]*entities.MPCMessage, error)

	// MarkDelivered marks a message as delivered
	MarkDelivered(ctx context.Context, messageID uuid.UUID) error

	// DeleteBySession deletes all messages for a session
	DeleteBySession(ctx context.Context, sessionID uuid.UUID) error

	// DeleteOlderThan deletes messages older than a specific time
	DeleteOlderThan(ctx context.Context, before time.Time) (int64, error)
}
