package supply

import (
	"context"
	"log"

	"bsm/full/module/ec/market/internal/impl"
	"bsm/full/module/ec/market/internal/models"
	pb "bsm/full/module/ec/market/pb"

	"git.apinb.com/bsm-sdk/core/service"
)

// 获取一个供应商
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.MarketSupplyItem, err error) {
	// parse authorization meta.
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	mktModel := models.MarketSupply{}
	if err := impl.DBService.Where("identity=?", in.GetIdentity()).First(&mktModel).Error; err != nil {
		log.Println("获取供应商数据失败：", err)
		return nil, err
	}

	return &pb.MarketSupplyItem{
		Id:       int32(mktModel.ID),
		Identity: mktModel.Identity,
		Name:     mktModel.Name,
		Avatar:   mktModel.Avatar,
		Account:  mktModel.Account,
		Phone:    mktModel.Phone,
		OrgName:  mktModel.OrgName,
		OrgPhoto: mktModel.OrgPhoto,
		IdName:   mktModel.IDName,
		IdBefore: mktModel.IDBefore,
		IdAfter:  mktModel.IDAfter,
		Remark:   mktModel.Remark,
	}, nil
}
