package job

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type RetryJobLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRetryJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RetryJobLogic {
	return &RetryJobLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *RetryJobLogic) RetryJob(req *types.JobIDPath) (*types.JobData, error) {
	run, err := l.svcCtx.Job.RetryRun(l.ctx, req.ID)
	if err != nil {
		return nil, err
	}
	data := toJobData(run)
	return &data, nil
}
