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

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

func (l *ClaimWorkerJobLogic) ClaimWorkerJob(req *types.ClaimWorkerJobReq) (resp *types.JobData, err error) {
	run, err := l.svcCtx.Job.ClaimNext(l.ctx, jobusecase.ClaimNextRequest{
		WorkerType: req.WorkerType,
		WorkerID:   req.WorkerID,
	})
	if err != nil || run == nil {
		return nil, err
	}
	data := ToJobData(run)
	return &data, nil
}
