package com.zm.order.tool.server.model;

import com.alibaba.fastjson.JSON;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.DiffBuilder;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.DiffResult;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.Diffable;
import com.aliyun.openservices.shade.org.apache.commons.lang3.builder.ToStringStyle;
import com.google.common.collect.Maps;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Map;
import java.util.Objects;

/**
 * 
 * @author mybatis-generator
 * @date   2020/12/01
 */
public class OrderPayDetails implements Diffable<OrderPayDetails> {

    /**
     * 主键
     */
    private Long id;

    /**
     * 订单号
     */
    private String orderNo;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 商家id
     */
    private Long sellerId;

    /**
     * 门店id
     */
    private Long storeId;

    /**
     * 支付类型
     */
    private Integer payType;

    /**
     * 付款金额
     */
    private Integer amount;

    /**
     * 支付单号
     */
    private String payNo;

    /**
     * 第三方支付单号
     */
    private String thirdPayNo;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 修改时间
     */
    private Date updatedAt;

    /**
     * 删除标识
     */
    private Integer isDeleted;

    /**
     * 下单时间
     */
    private Date orderAt;

    /**
     * 支付时间
     */
    private Date payAt;

    /**
     * 订单来源
     */
    private Integer source;

    /**
     * 订单类型
     */
    private Integer orderType;

    /**
     * 订单子类型
     */
    private Integer orderSubType;

    public Integer getOrderSubType() {
        return orderSubType;
    }

    public void setOrderSubType(Integer orderSubType) {
        this.orderSubType = orderSubType;
    }

    /**
     * 单个支付方式下，给商家贡献的实际收入 单位：分
     */
    private Integer incomeAmount;

    /**
     * 单个支付方式下，商家实际承担的平台抽成成本 单位：分
     */
    private Integer commissionAmount;

    /**
     * 扩展信息
     */
    private String features;

    /**
     * 扩展信息
     */
    private Map<String, Object> extraMap;

    private Integer status;

    /**
     * 业务类型
     */
    private Integer bizType;

    /**
     * 履约类型
     */
    private Integer performanceType;

    /**
     * 主数据源标记
     */
    private Integer masterDataSource;

    public Integer getIncomeAmount() {
        return incomeAmount;
    }

    public void setIncomeAmount(Integer incomeAmount) {
        this.incomeAmount = incomeAmount;
    }

    public Integer getCommissionAmount() {
        return commissionAmount;
    }

    public void setCommissionAmount(Integer commissionAmount) {
        this.commissionAmount = commissionAmount;
    }

    public Integer getMasterDataSource() {
        return masterDataSource;
    }

    public void setMasterDataSource(Integer masterDataSource) {
        this.masterDataSource = masterDataSource;
    }

    public Integer getBizType() {
        return bizType;
    }

    public void setBizType(Integer bizType) {
        this.bizType = bizType;
    }

    public Integer getPerformanceType() {
        return performanceType;
    }

    public void setPerformanceType(Integer performanceType) {
        this.performanceType = performanceType;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public String getFeatures() {
        return features;
    }

    public void setFeatures(String features) {
        this.features = features;
    }

    public Date getOrderAt() {
        return orderAt;
    }

    public void setOrderAt(Date orderAt) {
        this.orderAt = orderAt;
    }

    public Date getPayAt() {
        return payAt;
    }

    public void setPayAt(Date payAt) {
        this.payAt = payAt;
    }

    public String getPayNo() {
        return payNo;
    }

    public void setPayNo(String payNo) {
        this.payNo = payNo;
    }

    public String getThirdPayNo() {
        return thirdPayNo;
    }

    public void setThirdPayNo(String thirdPayNo) {
        this.thirdPayNo = thirdPayNo;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo == null ? null : orderNo.trim();
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getSellerId() {
        return sellerId;
    }

    public void setSellerId(Long sellerId) {
        this.sellerId = sellerId;
    }

    public Long getStoreId() {
        return storeId;
    }

    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }

    public Integer getPayType() {
        return payType;
    }

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

    public Integer getAmount() {
        return amount;
    }

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

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Integer getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Integer isDeleted) {
        this.isDeleted = isDeleted;
    }

    public Map<String, Object> getExtraMap() {
        if (!StringUtils.isEmpty(features)) {
            Map<String, Object> extra = JSON.parseObject(features, Map.class);
            return extra;
        }
        if (extraMap == null) {
            return Maps.newHashMap();
        }
        return extraMap;
    }

    public void setExtraMap(Map<String, Object> extraMap) {
        if (Objects.nonNull(extraMap) && !extraMap.isEmpty()) {
            this.features = JSON.toJSONString(extraMap);
        }
        this.extraMap = extraMap;
    }

    public void paint(DataStream data) {
        this.source = data.getSource();
        this.orderType = data.getOrderType();
        this.payType = data.getPayType();
        this.performanceType = data.getPerformanceType();
    }



    @Override
    public DiffResult diff(OrderPayDetails obj) {
        return new DiffBuilder(this, obj, ToStringStyle.JSON_STYLE)
                .append("storeId", this.storeId, obj.storeId)
                .append("payType", this.payType, obj.payType)
                .append("amount", this.amount, obj.amount)
                .append("payNo", this.payNo, obj.payNo)
                .append("thirdPayNo", this.thirdPayNo, obj.thirdPayNo)
                .append("payAt", this.payAt, obj.payAt)
                .append("source", this.source, obj.source)
                .append("orderType", this.orderType, obj.orderType)
                .append("features", this.features, obj.features)
                .append("isDeleted", this.isDeleted, obj.isDeleted)
                .append("status", this.status, obj.status)
                .build();
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}