package com.liquidnet.service.goblin.dto.vo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.liquidnet.service.goblin.entity.GoblinOrderAttr;
import com.liquidnet.service.goblin.entity.GoblinStoreOrder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 商城订单表
 * </p>
 *
 * @author liquidnet
 * @since 2021-12-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GoblinStoreOrderVo implements Serializable, Cloneable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = " 订单id")
    private String orderId;
    @ApiModelProperty(value = " 店铺id")
    private String storeId;
    @ApiModelProperty(value = " 店铺Name")
    private String storeName;
    @ApiModelProperty(value = " 主订单code  下单可能会同时下多个订单 ")
    private String masterOrderCode;
    @ApiModelProperty(value = " 订单号")
    private String orderCode;
    @ApiModelProperty(value = " 支付单号")
    private String payCode;
    @ApiModelProperty(value = " 用户id")
    private String userId;
    @ApiModelProperty(value = " 用户昵称")
    private String userName;
    @ApiModelProperty(value = " 用户手机号")
    private String userMobile;
    @ApiModelProperty(value = " 应付金额")
    private BigDecimal priceTotal;
    @ApiModelProperty(value = " 实付金额")
    private BigDecimal priceActual;
    @ApiModelProperty(value = " 退款价格")
    private BigDecimal priceRefund;
    @ApiModelProperty(value = " 商铺营销表id")
    private BigDecimal priceExpress;
    @ApiModelProperty(value = " 管理员修改优惠金额")
    private BigDecimal priceModify;
    @ApiModelProperty(value = "券优惠金额")
    private BigDecimal priceCoupon;
    @ApiModelProperty(value = "店铺券优惠金额")
    private BigDecimal storePriceCoupon;
    @ApiModelProperty(value = " 总优惠价格")
    private BigDecimal priceVoucher;
    @ApiModelProperty(value = "订单状态[0-待付款(用户刚下单)|2-代发货(用户付完款 等待商城发货)3-代收货(商城已经发货 等待用户确认收货)|4-已完成(用户已经确认收货 订单结束)|5-取消订单(用户未付款前取消订单)|6-退款通过(用户已经付款但是商城还未发货，用户发出退款申请，商城同意退款)|7-退货通过(用户已经确认收货后用户发出退货申请，商城同意所有退货申请 ，一个订单可能有多个单品)]")
    private Integer status;
    @ApiModelProperty(value = "正在下单是否出货[0-未出货|1-已出货]")
    private Integer zhengzaiStatus;
    @ApiModelProperty(value = " 券id")
    private String ucouponId;
    @ApiModelProperty(value = " 店铺券id")
    private String storeCouponId;
    @ApiModelProperty(value = " 支付类型[wepay-微信支付|alipay-阿里支付|douyinpay-抖音支付|unionpay-银联支付]")
    private String payType;
    @ApiModelProperty(value = " 支付来源")
    private String deviceFrom;
    @ApiModelProperty(value = " 取消原因")
    private String cancelReason;
    @ApiModelProperty(value = " 订单来源[app|h5|applet]")
    private String source;
    @ApiModelProperty(value = " 版本号")
    private String version;
    @ApiModelProperty(value = " 是否会员")
    private Integer isMember;
    @ApiModelProperty(value = "订单类型[0-普通订单|1-定金预售订单|2-全款预售订单|3-拼团订单|4-众筹全款|5-众筹1元|6-众筹无回报|7-虚拟商品订单|8-社区团购订单|9-正在下单]")
    private Integer orderType;
    @ApiModelProperty(value = " 支付时间")
    private String payTime;
    @ApiModelProperty(value = " 取消时间")
    private String cancelTime;
    @ApiModelProperty(value = " 管理员修改订单时间")
    private String modifyTime;
    @ApiModelProperty(value = " 抽奖状态[0-未抽奖|1-中奖|2-已抽奖]")
    private String lotteryStatus;
    @ApiModelProperty(value = " 虚拟订单核销码[正在支付取货码]")
    private String writeOffCode;
    @ApiModelProperty(value = " 订单过期时间(分钟)")
    private Integer payCountdownMinute;
    @ApiModelProperty(value = " 快递单号[废弃]")
    private String mailNo;
    @ApiModelProperty(value = " 发货时间[废弃]")
    private String deliveryTime;
    @ApiModelProperty(value = " 物流公司姓名[废弃]")
    private String logisticsCompany;
    @ApiModelProperty(value = " 物流公司code[物流公司id][废弃]")
    private String logisticsCode;
    @ApiModelProperty(value = " ip")
    private String ipAddress;
    @ApiModelProperty(value = " paymentId")
    private String paymentId;
    @ApiModelProperty(value = " paymentType")
    private String paymentType;
    @ApiModelProperty(value = " 活动类型[ZZ-正在下单]")
    private String marketType;
    @ApiModelProperty(value = " 活动id")
    private String marketId;
    @ApiModelProperty(value = " 创建时间")
    private String createdAt;
    @ApiModelProperty(value = " 创建时间")
    private int randomKey;

    @ApiModelProperty(value = "orderAttr")
    private GoblinOrderAttrVo orderAttrVo;
    @ApiModelProperty(value = "orderSkuId")
    private List<String> orderSkuVoIds;

    @ApiModelProperty(value = "混合售id")
    private String mixId;
    @ApiModelProperty(value = "混合售名称")
    private String mixName;
    @ApiModelProperty(value = "核销时间")
    private String pushTime;
    @ApiModelProperty(value = "ERP托管[0-否|1-是]，默认0")
    private Integer erpHosting;

    public String getPushTime() {
        return pushTime==null?"":pushTime;
    }

    public BigDecimal getPriceModify() {
        if (priceModify == null) {
            return BigDecimal.ZERO;
        }
        return priceModify;
    }

    public BigDecimal getPriceVoucher() {
        if (priceVoucher == null) {
            return BigDecimal.ZERO;
        }
        return priceVoucher;
    }

    public String getMixId() {
        return mixId == null ? "" : mixId;
    }

    public String getMixName() {
        return mixName == null ? "" : mixName;
    }


    public GoblinStoreOrderVo copy(GoblinStoreOrder source,int erpHosting) {
        if (null == source) return this;
        this.setOrderId(source.getOrderId());
        this.setStoreId(source.getStoreId());
        this.setStoreName(source.getStoreName());
        this.setMasterOrderCode(source.getMasterOrderCode());
        this.setOrderCode(source.getOrderCode());
        this.setPayCode(source.getPayCode());
        this.setUserId(source.getUserId());
        this.setUserName(source.getUserName());
        this.setUserMobile(source.getUserMobile());
        this.setPriceTotal(source.getPriceTotal());
        this.setPriceActual(source.getPriceActual());
        this.setPriceRefund(source.getPriceRefund());
        this.setPriceExpress(source.getPriceExpress());
        this.setPriceModify(source.getPriceModify());
        this.setPriceCoupon(source.getPriceCoupon());
        this.setStorePriceCoupon(source.getStorePriceCoupon());
        this.setPriceVoucher(source.getPriceVoucher());
        this.setStatus(source.getStatus());
        this.setZhengzaiStatus(source.getZhengzaiStatus());
        this.setUcouponId(source.getUcouponId());
        this.setStoreCouponId(source.getStoreCouponId());
        this.setPayType(source.getPayType());
        this.setDeviceFrom(source.getDeviceFrom());
        this.setCancelReason(source.getCancelReason());
        this.setSource(source.getSource());
        this.setVersion(source.getVersion());
        this.setIsMember(source.getIsMember());
        this.setOrderType(source.getOrderType());
//        this.setPayTime(source.getPayTime());
//        this.setCancelTime(source.getCancelTime());
//        this.setModifyTime(source.getModifyTime());
        this.setLotteryStatus(source.getLotteryStatus());
        this.setWriteOffCode(source.getWriteOffCode());
        this.setPayCountdownMinute(source.getPayCountdownMinute());
        this.setMailNo(source.getMailNo());
//        this.setDeliveryTime(source.getDeliveryTime());
        this.setLogisticsCompany(source.getLogisticsCompany());
        this.setLogisticsCode(source.getLogisticsCode());
        this.setIpAddress(source.getIpAddress());
        this.setPaymentId(source.getPaymentId());
        this.setPaymentType(source.getPaymentType());
        this.setMarketType(source.getMarketType());
        this.setMarketId(source.getMarketId());
//        this.setRandomKey(source.getrad());
        this.setCreatedAt(source.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        this.setErpHosting(erpHosting);
        return this;
    }

    public GoblinStoreOrderVo copyMix(GoblinStoreOrder source,String mixId,String mixName,int erpHosting) {
        if (null == source) return this;
        this.setOrderId(source.getOrderId());
        this.setStoreId(source.getStoreId());
        this.setStoreName(source.getStoreName());
        this.setMasterOrderCode(source.getMasterOrderCode());
        this.setOrderCode(source.getOrderCode());
        this.setPayCode(source.getPayCode());
        this.setUserId(source.getUserId());
        this.setUserName(source.getUserName());
        this.setUserMobile(source.getUserMobile());
        this.setPriceTotal(source.getPriceTotal());
        this.setPriceActual(source.getPriceActual());
        this.setPriceRefund(source.getPriceRefund());
        this.setPriceExpress(source.getPriceExpress());
        this.setPriceModify(source.getPriceModify());
        this.setPriceCoupon(source.getPriceCoupon());
        this.setStorePriceCoupon(source.getStorePriceCoupon());
        this.setPriceVoucher(source.getPriceVoucher());
        this.setStatus(source.getStatus());
        this.setZhengzaiStatus(source.getZhengzaiStatus());
        this.setUcouponId(source.getUcouponId());
        this.setStoreCouponId(source.getStoreCouponId());
        this.setPayType(source.getPayType());
        this.setDeviceFrom(source.getDeviceFrom());
        this.setCancelReason(source.getCancelReason());
        this.setSource(source.getSource());
        this.setVersion(source.getVersion());
        this.setIsMember(source.getIsMember());
        this.setOrderType(source.getOrderType());
        this.setLotteryStatus(source.getLotteryStatus());
        this.setWriteOffCode(source.getWriteOffCode());
        this.setPayCountdownMinute(source.getPayCountdownMinute());
        this.setMailNo(source.getMailNo());
        this.setLogisticsCompany(source.getLogisticsCompany());
        this.setLogisticsCode(source.getLogisticsCode());
        this.setIpAddress(source.getIpAddress());
        this.setPaymentId(source.getPaymentId());
        this.setPaymentType(source.getPaymentType());
        this.setMarketType(source.getMarketType());
        this.setMarketId(source.getMarketId());
        this.setCreatedAt(source.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        this.setMixId(mixId);
        this.setMixName(mixName);
        this.setErpHosting(erpHosting);
        return this;
    }

    private static final GoblinStoreOrderVo obj = new GoblinStoreOrderVo();

    public static GoblinStoreOrderVo getNew() {
        try {
            return (GoblinStoreOrderVo) obj.clone();
        } catch (CloneNotSupportedException e) {
            return new GoblinStoreOrderVo();
        }
    }
}
