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

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

// RestartList 重启任务列表
func (l *RestartListLogic) RestartList(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` = 'WaitRestart' 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", "WaitRestart")
	}
	return &result, nil
}
