package adapters

import (
	"context"
	"github.com/pkg/errors"

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

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

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

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

func (l *GetAdapterLogic) GetAdapter(req *types.AdapterDelReq) (resp *types.AdapterInfo, err error) {
	resp = &types.AdapterInfo{}
	db := l.svcCtx.DbEngin.Table("t_adapter").Where("id = ?", req.Id).First(&resp)
	if db.Error != nil {
		logx.Errorf("err %v", db.Error.Error())
		return nil, errors.New("Adapter does not exist")
	}
	return
}
