// Code generated by candi v1.4.0.

package workerhandler

import (
	"context"

	"monorepo/services/user-service/internal/modules/member/usecase"

	"pkg.agungdp.dev/candi/candihelper"
	"pkg.agungdp.dev/candi/codebase/factory/types"
	"pkg.agungdp.dev/candi/codebase/interfaces"
	"pkg.agungdp.dev/candi/tracer"
)

// CronHandler struct
type CronHandler struct {
	uc        usecase.MemberUsecase
	validator interfaces.Validator
}

// NewCronHandler constructor
func NewCronHandler(uc usecase.MemberUsecase, validator interfaces.Validator) *CronHandler {
	return &CronHandler{
		uc:        uc,
		validator: validator,
	}
}

// MountHandlers mount handler group
func (h *CronHandler) MountHandlers(group *types.WorkerHandlerGroup) {
	group.Add(candihelper.CronJobKeyToString("member-scheduler", "message", "10s"), h.handleMember)
}

func (h *CronHandler) handleMember(ctx context.Context, message []byte) error {
	trace := tracer.StartTrace(ctx, "MemberDeliveryCron:HandleMember")
	defer trace.Finish()
	ctx = trace.Context()

	return h.uc.AutoGenerateMember(ctx)
}
