// 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 CompleteWorkerJobLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *CompleteWorkerJobLogic) CompleteWorkerJob(req *types.WorkerCompleteReq) (resp *types.JobData, err error) {
	run, err := l.svcCtx.Job.CompleteRun(l.ctx, jobusecase.CompleteRunRequest{
		JobID:    req.ID,
		WorkerID: req.WorkerID,
		Result:   req.Result,
	})
	if err != nil {
		return nil, err
	}
	data := ToJobData(run)
	return &data, nil
}
