package com.bonus.core.pay.api.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.NumberUtil;
import com.bonus.constant.LeConstants;
import com.bonus.core.account.v3.api.dto.AccOrdBaseDTO;
import com.bonus.core.common.utils.JacksonUtil;
import com.bonus.core.customer.model.CustInfo;
import com.bonus.core.customer.vo.CustPayVO;
import com.bonus.core.device.manage.vo.DeviceInfoVO;
import com.bonus.core.marketing.v2.rule.price.dto.RulePriceResultDTO;
import com.bonus.core.order.common.model.OrderDetail;
import com.bonus.core.order.common.model.OrderInfo;
import com.bonus.core.order.utils.LeNumUtil;
import com.bonus.core.pay.common.constants.PayChannelSelectEnum;
import com.bonus.core.pay.common.constants.PayStateEnum;
import com.bonus.core.pay.common.dto.ChannelPayDTO;
import com.bonus.core.pay.common.model.TradeOrderRecharge;
import com.bonus.core.pay.common.model.TradeRecord;
import com.bonus.core.pay.common.vo.AndroidPayVO;
import com.bonus.core.pay.common.vo.PayChannelSelectResultVO;
import com.bonus.core.pay.common.vo.PayChannelSplitVO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.JsonNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class UnifyPayDTO {
   private static final Logger log = LoggerFactory.getLogger(UnifyPayDTO.class);
   private Integer scenario;
   private Integer ifTrail;
   private Integer ifFastAsyncPay;
   private Long tradeId;
   private Long relatedTradeId;
   private String outTradeNo;
   private BigDecimal amount;
   private Integer payType;
   private Integer payChannel;
   private Integer tradeType;
   private LocalDateTime startPayTime;
   private LocalDateTime orderTime;
   private Integer sourceType;
   private Long custId;
   private String custThirdId;
   private String custName;
   private String custNum;
   private String mobile;
   private Long orgId;
   private String orgNum;
   private String orgFullName;
   private Integer psnType;
   private String psnTypeName;
   private String custPhotoUrl;
   private String serialNum;
   private String thirdSerialNum;
   private LocalDate validityDate;
   private String machineName;
   private String machineSn;
   private String machineNum;
   private Integer nuClearMode;
   private String remark;
   private List<Order> orderList = CollUtil.newArrayList(new Order[0]);
   private List<Detail> detailList = CollUtil.newArrayList(new Detail[0]);
   private List<PayChannelSplitVO> payChannelSplits = CollUtil.newArrayList(new PayChannelSplitVO[0]);
   private RulePriceResultDTO rulePriceResult;
   private String couponId;
   private String openid;
   private String authCode;
   private String terminalParams;
   private String alipayContractNum;
   private Integer alipayFaceAsync;
   private String attach;
   private String abchDeviceKey;
   private String payPassword;
   private JsonNode extParam;

   public static UnifyPayDTO of(TradeRecord tradeRecord) {
      UnifyPayDTO unifyPayDTO = null;
      if (tradeRecord.getParam() != null) {
         unifyPayDTO = (UnifyPayDTO) JacksonUtil.treeToValue(tradeRecord.getParam(), UnifyPayDTO.class);
      }

      if (unifyPayDTO == null) {
         unifyPayDTO = new UnifyPayDTO();
         unifyPayDTO.setTradeId(tradeRecord.getId());
         unifyPayDTO.setAmount(tradeRecord.getAmount());
         unifyPayDTO.setTradeType(tradeRecord.getTradeType());
         unifyPayDTO.setPayType(tradeRecord.getPayType());
         unifyPayDTO.setPayChannel(tradeRecord.getPayChannel());
         unifyPayDTO.setStartPayTime(tradeRecord.getCreateTime());
         unifyPayDTO.setCustId(tradeRecord.getCustId());
         unifyPayDTO.setSourceType(tradeRecord.getSourceType());
      }

      return unifyPayDTO;
   }

   public static UnifyPayDTO of(PayChannelSelectResultVO resultVO) {
      UnifyPayDTO unifyPayDTO = new UnifyPayDTO();
      unifyPayDTO.setPayType(resultVO.getPayType());
      unifyPayDTO.setPayChannel(resultVO.getPayChannel());
      unifyPayDTO.setPayChannelSplits(resultVO.getPayChannelSplits());
      unifyPayDTO.setCouponId(resultVO.getCouponId());
      unifyPayDTO.setOpenid(resultVO.getOpenId());
      unifyPayDTO.setAlipayContractNum(resultVO.getAlipayContractNum());
      if (resultVO.getCustPayVO() != null) {
         unifyPayDTO.setValidityDate(resultVO.getCustPayVO().getValidityDate());
         unifyPayDTO.fillCustInfo(resultVO.getCustPayVO());
      }

      return unifyPayDTO;
   }

   public static String[] logFields() {
      return new String[]{"tradeId", "amount", "payType", "payChannel", "tradeType", "custId", "custName", "custNum", "openid", "couponId", "sourceType", "remark", "attach", "thirdSerialNum", "custThirdId", "canteenId", "canteenName", "stallId", "stallName", "mealtimeType", "mealtimeName", "orderTime", "authCode", "terminalParams", "serialNum", "machineSn", "machineNum", "nuClearMode", "mktTimeQuotaPayDTO", "rulePriceResult"};
   }

   public static String[] logFieldsAmount() {
      return new String[]{"tradeId", "amount", "payType", "payChannel", "tradeType", "custId", "couponId", "sourceType", "mktTimeQuotaPayDTO", "rulePriceResult"};
   }

   public Integer getOnlineState() {
      return PayChannelSelectEnum.isDeviceOffline(this.scenario) ? LeConstants.COMMON_NO : LeConstants.COMMON_YES;
   }

   @JsonIgnore
   public boolean isDeviceOffline() {
      return PayChannelSelectEnum.isDeviceOffline(this.scenario);
   }

   public boolean containsRuleWalletDetail() {
      return this.rulePriceResult != null && CollUtil.isNotEmpty(this.rulePriceResult.getWalletDetails());
   }

   public Long getCanteenId() {
      return (Long)LeNumUtil.reduceField(this.getOrderList(), Order::getCanteenId, (Object)null);
   }

   public Long getStallId() {
      return (Long)LeNumUtil.reduceField(this.getOrderList(), Order::getStallId, (Object)null);
   }

   public String getMacOrderId() {
      return (String)LeNumUtil.reduceField(this.getOrderList(), Order::getMacOrderId, (Object)null);
   }

   public <T> T reduceOrderField(Function<Order, T> func, T defaultValue) {
      return LeNumUtil.reduceField(this.orderList, func, defaultValue);
   }

   public void fillCustInfo(CustPayVO custPayVO) {
      if (custPayVO != null) {
         this.custId = custPayVO.getCustId();
         this.custThirdId = custPayVO.getCustThirdId();
         this.custName = custPayVO.getCustName();
         this.custNum = custPayVO.getCustNum();
         this.psnType = custPayVO.getPsnType();
         this.psnTypeName = custPayVO.getPsnTypeName();
         this.mobile = custPayVO.getMobile();
         this.orgId = custPayVO.getOrgId();
         this.orgNum = custPayVO.getOrgNum();
         this.orgFullName = custPayVO.getOrgFullName();
         this.custPhotoUrl = custPayVO.getCustPhotoUrl();
         this.serialNum = custPayVO.getSerialNum();
         this.thirdSerialNum = custPayVO.getThirdSerialNum();
         this.validityDate = custPayVO.getValidityDate();
      }
   }

   public void fillCustInfo(CustInfo custInfo) {
      if (custInfo != null) {
         this.custId = custInfo.getCustId();
         this.custThirdId = custInfo.getCustThirdId();
         this.custName = custInfo.getCustName();
         this.custNum = custInfo.getCustNum();
         this.psnType = custInfo.getPsnType();
         this.psnTypeName = custInfo.getPsnTypeName();
         this.mobile = custInfo.getMobile();
         this.orgId = custInfo.getOrgId();
         this.orgNum = custInfo.getOrgNum();
         this.orgFullName = custInfo.getOrgFullName();
         this.custPhotoUrl = custInfo.getCustPhotoUrl();
      }
   }

   public void fillCustInfoIfNecessary(AndroidPayVO androidPayVO) {
      if (!LeNumUtil.isValidId(this.custId) && LeNumUtil.isValidId(androidPayVO.getCustId())) {
         this.custId = androidPayVO.getCustId();
      }

      if (CharSequenceUtil.isBlank(this.custName) && CharSequenceUtil.isNotBlank(androidPayVO.getCustName())) {
         this.custName = androidPayVO.getCustName();
      }

      if (CharSequenceUtil.isBlank(this.orgFullName) && CharSequenceUtil.isNotBlank(androidPayVO.getOrgFullName())) {
         this.orgFullName = androidPayVO.getOrgFullName();
      }

   }

   public void fillDeviceInfo(DeviceInfoVO deviceInfoVO) {
      if (deviceInfoVO != null) {
         this.machineName = deviceInfoVO.getDeviceName();
         this.machineSn = deviceInfoVO.getDeviceSn();
         this.machineNum = deviceInfoVO.getDeviceNum();
         this.sourceType = deviceInfoVO.getDeviceType();
      }
   }

   public TradeRecord toTradeRecord() {
      TradeRecord tradeRecord = new TradeRecord();
      tradeRecord.setId(this.getTradeId());
      tradeRecord.setRelatedTradeId(this.getRelatedTradeId());
      tradeRecord.setAmount(this.getAmount());
      tradeRecord.setTradeState(PayStateEnum.PAY_INPROCESS.getKey());
      tradeRecord.setTradeType(this.getTradeType());
      tradeRecord.setPayType(this.getPayType());
      tradeRecord.setPayChannel(this.getPayChannel());
      tradeRecord.setCustId(this.getCustId());
      tradeRecord.setSourceType(this.getSourceType());
      tradeRecord.setCanteenId((Long)LeNumUtil.reduceField(this.getOrderList(), Order::getCanteenId, (Object)null));
      tradeRecord.setOutTradeNo(this.getOutTradeNo());
      tradeRecord.setParam(JacksonUtil.valueToTreeIgnoreNull(this));
      return tradeRecord;
   }

   public List<TradeOrderRecharge> toTradeOrderRechargeList() {
      return (List)(CollUtil.isEmpty(this.orderList) ? CollUtil.newArrayList(new TradeOrderRecharge[0]) : (List)this.orderList.stream().map((s) -> {
         TradeOrderRecharge tradeOrderRecharge = new TradeOrderRecharge();
         tradeOrderRecharge.setTradeId(this.tradeId);
         tradeOrderRecharge.setOrderRechargeId(s.getOrderId());
         tradeOrderRecharge.setMacOrderId(s.getMacOrderId());
         return tradeOrderRecharge;
      }).collect(Collectors.toList()));
   }

   public ChannelPayDTO convertToChannelPayDTO() {
      ChannelPayDTO channelPayDTO = (ChannelPayDTO)BeanUtil.copyProperties(this, ChannelPayDTO.class, new String[0]);
      channelPayDTO.setTradeChannelId(this.tradeId);
      return channelPayDTO;
   }

   public AccOrdBaseDTO convertToAccPayDTO() {
      AccOrdBaseDTO accPayDTO = (AccOrdBaseDTO)BeanUtil.copyProperties(this, AccOrdBaseDTO.class, new String[0]);
      accPayDTO.setCustId(this.getCustId());
      accPayDTO.setOrderId(this.getTradeId());
      accPayDTO.setIfTrialCalculation(false);
      if (this.getRulePriceResult() != null) {
         accPayDTO.setRulePriceResult(this.getRulePriceResult());
      } else {
         accPayDTO.setRulePriceResult((new RulePriceResultDTO()).setRealAmount(this.getAmount()));
      }

      if (!NumberUtil.equals(this.getAmount(), accPayDTO.getRulePriceResult().getRealAmount())) {
         log.warn("发起支付金额与消费规则结果金额不一致：{}，{}", this.getAmount(), this.getRulePriceResult().getRealAmount());
         this.getRulePriceResult().setRealAmount(this.getAmount());
      }

      accPayDTO.setCanteenId((Long)this.reduceOrderField(Order::getCanteenId, (Object)null));
      accPayDTO.setCanteenName((String)this.reduceOrderField(Order::getCanteenName, (Object)null));
      accPayDTO.setShopstallId((Long)this.reduceOrderField(Order::getStallId, (Object)null));
      accPayDTO.setShopstallName((String)this.reduceOrderField(Order::getStallName, (Object)null));
      accPayDTO.setMchNum(this.getMachineNum());
      accPayDTO.setMchSn(this.getMachineSn());
      accPayDTO.setOrdTime(this.getOrderTime());
      accPayDTO.setNuClearMode(this.getNuClearMode());
      accPayDTO.setIfOnline(this.getOnlineState());
      accPayDTO.setRemark(this.getRemark());
      accPayDTO.setSourceType(this.getSourceType());
      accPayDTO.setOrderType(CollUtil.isNotEmpty(this.getOrderList()) ? ((Order)this.getOrderList().get(0)).getOrderType() : null);
      return accPayDTO;
   }

   public Integer getScenario() {
      return this.scenario;
   }

   public Integer getIfTrail() {
      return this.ifTrail;
   }

   public Integer getIfFastAsyncPay() {
      return this.ifFastAsyncPay;
   }

   public Long getTradeId() {
      return this.tradeId;
   }

   public Long getRelatedTradeId() {
      return this.relatedTradeId;
   }

   public String getOutTradeNo() {
      return this.outTradeNo;
   }

   public BigDecimal getAmount() {
      return this.amount;
   }

   public Integer getPayType() {
      return this.payType;
   }

   public Integer getPayChannel() {
      return this.payChannel;
   }

   public Integer getTradeType() {
      return this.tradeType;
   }

   public LocalDateTime getStartPayTime() {
      return this.startPayTime;
   }

   public LocalDateTime getOrderTime() {
      return this.orderTime;
   }

   public Integer getSourceType() {
      return this.sourceType;
   }

   public Long getCustId() {
      return this.custId;
   }

   public String getCustThirdId() {
      return this.custThirdId;
   }

   public String getCustName() {
      return this.custName;
   }

   public String getCustNum() {
      return this.custNum;
   }

   public String getMobile() {
      return this.mobile;
   }

   public Long getOrgId() {
      return this.orgId;
   }

   public String getOrgNum() {
      return this.orgNum;
   }

   public String getOrgFullName() {
      return this.orgFullName;
   }

   public Integer getPsnType() {
      return this.psnType;
   }

   public String getPsnTypeName() {
      return this.psnTypeName;
   }

   public String getCustPhotoUrl() {
      return this.custPhotoUrl;
   }

   public String getSerialNum() {
      return this.serialNum;
   }

   public String getThirdSerialNum() {
      return this.thirdSerialNum;
   }

   public LocalDate getValidityDate() {
      return this.validityDate;
   }

   public String getMachineName() {
      return this.machineName;
   }

   public String getMachineSn() {
      return this.machineSn;
   }

   public String getMachineNum() {
      return this.machineNum;
   }

   public Integer getNuClearMode() {
      return this.nuClearMode;
   }

   public String getRemark() {
      return this.remark;
   }

   public List<Order> getOrderList() {
      return this.orderList;
   }

   public List<Detail> getDetailList() {
      return this.detailList;
   }

   public List<PayChannelSplitVO> getPayChannelSplits() {
      return this.payChannelSplits;
   }

   public RulePriceResultDTO getRulePriceResult() {
      return this.rulePriceResult;
   }

   public String getCouponId() {
      return this.couponId;
   }

   public String getOpenid() {
      return this.openid;
   }

   public String getAuthCode() {
      return this.authCode;
   }

   public String getTerminalParams() {
      return this.terminalParams;
   }

   public String getAlipayContractNum() {
      return this.alipayContractNum;
   }

   public Integer getAlipayFaceAsync() {
      return this.alipayFaceAsync;
   }

   public String getAttach() {
      return this.attach;
   }

   public String getAbchDeviceKey() {
      return this.abchDeviceKey;
   }

   public String getPayPassword() {
      return this.payPassword;
   }

   public JsonNode getExtParam() {
      return this.extParam;
   }

   public void setScenario(final Integer scenario) {
      this.scenario = scenario;
   }

   public void setIfTrail(final Integer ifTrail) {
      this.ifTrail = ifTrail;
   }

   public void setIfFastAsyncPay(final Integer ifFastAsyncPay) {
      this.ifFastAsyncPay = ifFastAsyncPay;
   }

   public void setTradeId(final Long tradeId) {
      this.tradeId = tradeId;
   }

   public void setRelatedTradeId(final Long relatedTradeId) {
      this.relatedTradeId = relatedTradeId;
   }

   public void setOutTradeNo(final String outTradeNo) {
      this.outTradeNo = outTradeNo;
   }

   public void setAmount(final BigDecimal amount) {
      this.amount = amount;
   }

   public void setPayType(final Integer payType) {
      this.payType = payType;
   }

   public void setPayChannel(final Integer payChannel) {
      this.payChannel = payChannel;
   }

   public void setTradeType(final Integer tradeType) {
      this.tradeType = tradeType;
   }

   public void setStartPayTime(final LocalDateTime startPayTime) {
      this.startPayTime = startPayTime;
   }

   public void setOrderTime(final LocalDateTime orderTime) {
      this.orderTime = orderTime;
   }

   public void setSourceType(final Integer sourceType) {
      this.sourceType = sourceType;
   }

   public void setCustId(final Long custId) {
      this.custId = custId;
   }

   public void setCustThirdId(final String custThirdId) {
      this.custThirdId = custThirdId;
   }

   public void setCustName(final String custName) {
      this.custName = custName;
   }

   public void setCustNum(final String custNum) {
      this.custNum = custNum;
   }

   public void setMobile(final String mobile) {
      this.mobile = mobile;
   }

   public void setOrgId(final Long orgId) {
      this.orgId = orgId;
   }

   public void setOrgNum(final String orgNum) {
      this.orgNum = orgNum;
   }

   public void setOrgFullName(final String orgFullName) {
      this.orgFullName = orgFullName;
   }

   public void setPsnType(final Integer psnType) {
      this.psnType = psnType;
   }

   public void setPsnTypeName(final String psnTypeName) {
      this.psnTypeName = psnTypeName;
   }

   public void setCustPhotoUrl(final String custPhotoUrl) {
      this.custPhotoUrl = custPhotoUrl;
   }

   public void setSerialNum(final String serialNum) {
      this.serialNum = serialNum;
   }

   public void setThirdSerialNum(final String thirdSerialNum) {
      this.thirdSerialNum = thirdSerialNum;
   }

   public void setValidityDate(final LocalDate validityDate) {
      this.validityDate = validityDate;
   }

   public void setMachineName(final String machineName) {
      this.machineName = machineName;
   }

   public void setMachineSn(final String machineSn) {
      this.machineSn = machineSn;
   }

   public void setMachineNum(final String machineNum) {
      this.machineNum = machineNum;
   }

   public void setNuClearMode(final Integer nuClearMode) {
      this.nuClearMode = nuClearMode;
   }

   public void setRemark(final String remark) {
      this.remark = remark;
   }

   public void setOrderList(final List<Order> orderList) {
      this.orderList = orderList;
   }

   public void setDetailList(final List<Detail> detailList) {
      this.detailList = detailList;
   }

   public void setPayChannelSplits(final List<PayChannelSplitVO> payChannelSplits) {
      this.payChannelSplits = payChannelSplits;
   }

   public void setRulePriceResult(final RulePriceResultDTO rulePriceResult) {
      this.rulePriceResult = rulePriceResult;
   }

   public void setCouponId(final String couponId) {
      this.couponId = couponId;
   }

   public void setOpenid(final String openid) {
      this.openid = openid;
   }

   public void setAuthCode(final String authCode) {
      this.authCode = authCode;
   }

   public void setTerminalParams(final String terminalParams) {
      this.terminalParams = terminalParams;
   }

   public void setAlipayContractNum(final String alipayContractNum) {
      this.alipayContractNum = alipayContractNum;
   }

   public void setAlipayFaceAsync(final Integer alipayFaceAsync) {
      this.alipayFaceAsync = alipayFaceAsync;
   }

   public void setAttach(final String attach) {
      this.attach = attach;
   }

   public void setAbchDeviceKey(final String abchDeviceKey) {
      this.abchDeviceKey = abchDeviceKey;
   }

   public void setPayPassword(final String payPassword) {
      this.payPassword = payPassword;
   }

   public void setExtParam(final JsonNode extParam) {
      this.extParam = extParam;
   }


   public static class Order {
      private Integer orderType;
      private Long orderId;
      private String macOrderId;
      private Long canteenId;
      private String canteenName;
      private Long stallId;
      private String stallName;
      private Integer mealtimeType;
      private String mealtimeName;
      private LocalDateTime orderTime;
      private BigDecimal amount;

      public static Order of(OrderInfo orderInfo) {
         Order order = (Order)BeanUtil.copyProperties(orderInfo, Order.class, new String[0]);
         order.setAmount(orderInfo.calcNeedPayAmount());
         return order;
      }

      public Integer getOrderType() {
         return this.orderType;
      }

      public Long getOrderId() {
         return this.orderId;
      }

      public String getMacOrderId() {
         return this.macOrderId;
      }

      public Long getCanteenId() {
         return this.canteenId;
      }

      public String getCanteenName() {
         return this.canteenName;
      }

      public Long getStallId() {
         return this.stallId;
      }

      public String getStallName() {
         return this.stallName;
      }

      public Integer getMealtimeType() {
         return this.mealtimeType;
      }

      public String getMealtimeName() {
         return this.mealtimeName;
      }

      public LocalDateTime getOrderTime() {
         return this.orderTime;
      }

      public BigDecimal getAmount() {
         return this.amount;
      }

      public Order setOrderType(final Integer orderType) {
         this.orderType = orderType;
         return this;
      }

      public Order setOrderId(final Long orderId) {
         this.orderId = orderId;
         return this;
      }

      public Order setMacOrderId(final String macOrderId) {
         this.macOrderId = macOrderId;
         return this;
      }

      public Order setCanteenId(final Long canteenId) {
         this.canteenId = canteenId;
         return this;
      }

      public Order setCanteenName(final String canteenName) {
         this.canteenName = canteenName;
         return this;
      }

      public Order setStallId(final Long stallId) {
         this.stallId = stallId;
         return this;
      }

      public Order setStallName(final String stallName) {
         this.stallName = stallName;
         return this;
      }

      public Order setMealtimeType(final Integer mealtimeType) {
         this.mealtimeType = mealtimeType;
         return this;
      }

      public Order setMealtimeName(final String mealtimeName) {
         this.mealtimeName = mealtimeName;
         return this;
      }

      public Order setOrderTime(final LocalDateTime orderTime) {
         this.orderTime = orderTime;
         return this;
      }

      public Order setAmount(final BigDecimal amount) {
         this.amount = amount;
         return this;
      }
   }

   public static class Detail {
      private Long detailId;
      private Long orderId;
      private Long goodsDishesId;
      private Long menuDetailId;
      private String inventoryId;
      private String goodsDishesName;
      private Integer price;
      private Integer weightUnit;
      private Integer quantity;
      private Integer salesMode;
      private Integer totalAmount;
      private Integer detailType;
      private String tasteName;
      private BigDecimal amount;

      public static Detail of(OrderDetail orderDetail) {
         Detail detail = (Detail)BeanUtil.copyProperties(orderDetail, Detail.class, new String[0]);
         detail.setAmount(orderDetail.getCalcTotalAmount());
         return detail;
      }

      public Long getDetailId() {
         return this.detailId;
      }

      public Long getOrderId() {
         return this.orderId;
      }

      public Long getGoodsDishesId() {
         return this.goodsDishesId;
      }

      public Long getMenuDetailId() {
         return this.menuDetailId;
      }

      public String getInventoryId() {
         return this.inventoryId;
      }

      public String getGoodsDishesName() {
         return this.goodsDishesName;
      }

      public Integer getPrice() {
         return this.price;
      }

      public Integer getWeightUnit() {
         return this.weightUnit;
      }

      public Integer getQuantity() {
         return this.quantity;
      }

      public Integer getSalesMode() {
         return this.salesMode;
      }

      public Integer getTotalAmount() {
         return this.totalAmount;
      }

      public Integer getDetailType() {
         return this.detailType;
      }

      public String getTasteName() {
         return this.tasteName;
      }

      public BigDecimal getAmount() {
         return this.amount;
      }

      public Detail setDetailId(final Long detailId) {
         this.detailId = detailId;
         return this;
      }

      public Detail setOrderId(final Long orderId) {
         this.orderId = orderId;
         return this;
      }

      public Detail setGoodsDishesId(final Long goodsDishesId) {
         this.goodsDishesId = goodsDishesId;
         return this;
      }

      public Detail setMenuDetailId(final Long menuDetailId) {
         this.menuDetailId = menuDetailId;
         return this;
      }

      public Detail setInventoryId(final String inventoryId) {
         this.inventoryId = inventoryId;
         return this;
      }

      public Detail setGoodsDishesName(final String goodsDishesName) {
         this.goodsDishesName = goodsDishesName;
         return this;
      }

      public Detail setPrice(final Integer price) {
         this.price = price;
         return this;
      }

      public Detail setWeightUnit(final Integer weightUnit) {
         this.weightUnit = weightUnit;
         return this;
      }

      public Detail setQuantity(final Integer quantity) {
         this.quantity = quantity;
         return this;
      }

      public Detail setSalesMode(final Integer salesMode) {
         this.salesMode = salesMode;
         return this;
      }

      public Detail setTotalAmount(final Integer totalAmount) {
         this.totalAmount = totalAmount;
         return this;
      }

      public Detail setDetailType(final Integer detailType) {
         this.detailType = detailType;
         return this;
      }

      public Detail setTasteName(final String tasteName) {
         this.tasteName = tasteName;
         return this;
      }

      public Detail setAmount(final BigDecimal amount) {
         this.amount = amount;
         return this;
      }

   }
}
