package apps

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
	"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
)

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

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

func (l *GetAppByAppNameLogic) GetAppByAppName(req *types.AppDetailReq) (resp interface{}, err error) {
	var task Task
	db := l.svcCtx.DbEngin.Raw("select * from task where ns_id = ? and name = ? AND deleted_at IS NULL", req.NsID, req.Name).Scan(&task)
	if db.Error != nil {
		logx.Errorf("db error: %v", db.Error)
		return
	}
	resp = task.YamlString
	return
}
