package summary

import (
	"context"

	"bsm/full/module/ec/order/internal/logic/common"
	pb "bsm/full/module/ec/order/pb"

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

// 获取一个订单的详情数据
func Get(ctx context.Context, in *pb.OrderIdentRequest) (reply *pb.SummaryGetReply, err error) {
	// parse authorization meta.
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	// valildate request id,identity.
	if in.Identity == "" {
		return nil, errcode.ErrInvalidArgument
	}

	summary, err := common.GetOrderSummaryByIdentity(in.Identity)
	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.SummaryGetReply{
		Summary: summary,
	}, nil
}
