package common

import (
	"bsm/full/module/ec/order/internal/models"
	pb "bsm/full/module/ec/order/pb"
)

// GetOrderSummaryByIdentity 根据订单号获取订单详情
func GetOrderSummaryByIdentity(identity string) (*pb.OrderSummaryItem, error) {
	var (
		err     error
		summary = new(models.OrderSummary)
	)
	err = models.DBService.Preload("OrderDetails").Where("identity = ?", identity).First(&summary).Error
	if err != nil {
		return nil, err
	}

	return ReflectProtoOrderSummary(summary), nil
}

func GetOrderSummaryByNo(no string) (*pb.OrderSummaryItem, error) {
	var (
		err     error
		summary = new(models.OrderSummary)
	)
	err = models.DBService.Preload("OrderDetails").Where("order_no = ?", no).First(&summary).Error
	if err != nil {
		return nil, err
	}

	return ReflectProtoOrderSummary(summary), nil
}
