// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package job

import (
	"context"

	jobusecase "haixun-backend/internal/model/job/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AckWorkerJobCancelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAckWorkerJobCancelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AckWorkerJobCancelLogic {
	return &AckWorkerJobCancelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AckWorkerJobCancelLogic) AckWorkerJobCancel(req *types.WorkerJobReq) (resp *types.JobData, err error) {
	run, err := l.svcCtx.Job.AcknowledgeCancel(l.ctx, jobusecase.AcknowledgeCancelRequest{
		JobID:    req.ID,
		WorkerID: req.WorkerID,
	})
	if err != nil {
		return nil, err
	}
	data := ToJobData(run)
	return &data, nil
}
