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

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

func (l *UpdateWorkerJobProgressLogic) UpdateWorkerJobProgress(req *types.WorkerProgressReq) (resp *types.JobData, err error) {
	run, err := l.svcCtx.Job.UpdateProgress(l.ctx, jobusecase.UpdateProgressRequest{
		JobID:      req.ID,
		WorkerID:   req.WorkerID,
		Phase:      req.Phase,
		Summary:    req.Summary,
		Percentage: req.Percentage,
		Steps:      toEntitySteps(req.Steps),
	})
	if err != nil {
		return nil, err
	}
	data := ToJobData(run)
	return &data, nil
}
