package product

import (
	"context"

	"bsm/full/module/ec/mall/internal/impl"
	"bsm/full/module/ec/mall/internal/models"
	pb "bsm/full/module/ec/mall/pb"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
)

// DetailSpec 产品详情
func SpecDetail(ctx context.Context, in *pb.IdentRequest) (reply *pb.SpecItem, err error) {
	if in.GetIdentity() == "" {
		return nil, errcode.ErrInvalidArgument
	}

	var data models.MallProductSpec
	err = impl.DBService.Model(&models.MallProductSpec{}).Where("identity = ?", in.Identity).First(&data).Error

	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}
	return &pb.SpecItem{
		Id:              int64(data.ID),
		Identity:        data.Identity,
		SupplyId:        data.SupplyId,
		Title:           data.Title,
		StockType:       data.StockType,
		Stock:           data.Stock,
		Price:           data.Price,
		DirectSales:     data.DirectSales,
		TpType:          data.TpType,
		DsTpType:        data.DsTpType,
		Img:             data.Img,
		PurchasingPrice: data.PurchasingPrice,
		Wholesale:       data.Wholesale,
	}, nil
}
