package participantservicelogic

import (
	"context"

	"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/internal/svc"
	"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/pcmCore"

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

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

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

// StartList 启动任务列表
func (l *StartListLogic) StartList(in *pcmCore.ApplyListReq) (*pcmCore.ApplyListResp, error) {
	result := pcmCore.ApplyListResp{
		InfoList: make([]*pcmCore.ApplyInfo, 0),
	}
	l.svcCtx.DbEngin.Raw("SELECT sppi.`name` as ParticipantName, c.ns_id as namespace,c.name as name , c.kind as kind FROM cloud c,sc_participant_phy_info sppi where c.`status` = 'WaitStart' and sppi.id = c.participant_id and deleted_at is null").Scan(&result.InfoList)
	if len(result.InfoList) != 0 {
		l.svcCtx.DbEngin.Exec("update cloud set status = ? where status = ?", "Issued", "WaitStart")
	}
	return &result, nil
}
