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

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

// applyList 执行任务列表
func (l *ApplyListLogic) ApplyList(in *pcmCore.ApplyListReq) (*pcmCore.ApplyListResp, error) {
	result := pcmCore.ApplyListResp{
		InfoList: make([]*pcmCore.ApplyInfo, 0),
	}
	l.svcCtx.DbEngin.Raw("SELECT sppi.`name` as ParticipantName,c.yaml_string as YamlString FROM cloud c,sc_participant_phy_info sppi where c.`status` = 'Saved' and sppi.id = c.participant_id").Scan(&result.InfoList)
	if len(result.InfoList) != 0 {
		l.svcCtx.DbEngin.Exec("update cloud set status = ? where status = ?", "Issued", "Saved")
	}
	return &result, nil
}
