// codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/usecase/blockedemail/list.go
package blockedemail

import (
	"context"

	"go.uber.org/zap"

	"github.com/gocql/gocql"
	dom_blockedemail "codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/domain/blockedemail"
)

type ListBlockedEmailsUseCase interface {
	Execute(ctx context.Context, userID gocql.UUID) ([]*dom_blockedemail.BlockedEmail, error)
}

type listBlockedEmailsUseCaseImpl struct {
	logger *zap.Logger
	repo   dom_blockedemail.BlockedEmailRepository
}

func NewListBlockedEmailsUseCase(
	logger *zap.Logger,
	repo dom_blockedemail.BlockedEmailRepository,
) ListBlockedEmailsUseCase {
	logger = logger.Named("ListBlockedEmailsUseCase")
	return &listBlockedEmailsUseCaseImpl{
		logger: logger,
		repo:   repo,
	}
}

func (uc *listBlockedEmailsUseCaseImpl) Execute(ctx context.Context, userID gocql.UUID) ([]*dom_blockedemail.BlockedEmail, error) {
	blockedEmails, err := uc.repo.List(ctx, userID)
	if err != nil {
		uc.logger.Error("Failed to list blocked emails",
			zap.Any("error", err),
			zap.Any("user_id", userID))
		return nil, err
	}

	uc.logger.Debug("Listed blocked emails",
		zap.Any("user_id", userID),
		zap.Int("count", len(blockedEmails)))

	return blockedEmails, nil
}
