package task

import (
	"context"

	"github.com/hibiken/asynq"
	"go.uber.org/zap"

	notificationinfra "github.com/break/junhong_cmp_fiber/internal/infrastructure/notification"
)

// NotificationCleanupHandler 处理低峰通知保留清理任务。
type NotificationCleanupHandler struct {
	service *notificationinfra.CleanupService
	logger  *zap.Logger
}

// NewNotificationCleanupHandler 创建通知保留清理任务处理器。
func NewNotificationCleanupHandler(service *notificationinfra.CleanupService, logger *zap.Logger) *NotificationCleanupHandler {
	return &NotificationCleanupHandler{service: service, logger: logger}
}

// Handle 执行有界、可重入的通知分批清理。
func (h *NotificationCleanupHandler) Handle(ctx context.Context, _ *asynq.Task) error {
	h.logger.Info("开始执行站内通知保留清理")
	if err := h.service.Run(ctx); err != nil {
		h.logger.Error("站内通知保留清理失败", zap.String("failure_category", "database"), zap.Error(err))
		return err
	}
	return nil
}
