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 2019/10/28
 */
public class OrderDiscount implements Diffable<OrderDiscount> {

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

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

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

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

    /**
     * 商品id
     */
    private String itemId;

    /**
     * 优惠级别
     */
    private Integer discountLevel;

    /**
     * 优惠id
     */
    private String discountId;

    /**
     * 优惠类型
     */
    private Integer discountType;

    /**
     * 优惠名称
     */
    private String discountName;

    /**
     * 优惠描述
     */
    private String discountSummary;

    /**
     * 优惠金额
     */
    private Integer discountAmount;

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

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

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

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

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

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

    /**
     * 商家id
     */
    private Integer status;

    /**
     * 单个优惠方式下给商家贡献的实际收入 单位：分',
     */
    private Integer incomeAmount;

    /**
     * 单个优惠方式下平台对于各种优惠的抽成 单位：分',
     */
    private Integer commissionAmount;

    /**
     * 订单优惠分摊标识，用于关联订单级优惠下的商品级优惠
     */
    private String uniqueKey;

    /**
     * 优惠文案
     */
    private String discountText;

    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 String getUniqueKey() {
        return uniqueKey;
    }

    public void setUniqueKey(String uniqueKey) {
        this.uniqueKey = uniqueKey;
    }

    public Integer getStatus() {
        return status;
    }

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

    public String getDiscountText() {
        return discountText;
    }

    public void setDiscountText(String discountText) {
        this.discountText = discountText;
    }

    public Long getSellerId() {
        return sellerId;
    }

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

    public Integer getBizType() {
        return bizType;
    }

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

    public Long getId() {
        return id;
    }

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

    public Long getUserId() {
        return userId;
    }

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

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public Integer getDiscountLevel() {
        return discountLevel;
    }

    public void setDiscountLevel(Integer discountLevel) {
        this.discountLevel = discountLevel;
    }

    public String getDiscountId() {
        return discountId;
    }

    public void setDiscountId(String discountId) {
        this.discountId = discountId;
    }

    public Integer getDiscountType() {
        return discountType;
    }

    public void setDiscountType(Integer discountType) {
        this.discountType = discountType;
    }

    public String getDiscountName() {
        return discountName;
    }

    public void setDiscountName(String discountName) {
        this.discountName = discountName;
    }

    public String getDiscountSummary() {
        return discountSummary;
    }

    public void setDiscountSummary(String discountSummary) {
        this.discountSummary = discountSummary;
    }

    public Integer getDiscountAmount() {
        return discountAmount;
    }

    public void setDiscountAmount(Integer discountAmount) {
        this.discountAmount = discountAmount;
    }

    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 String getFeatures() {
        return features;
    }

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

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

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


    @Override
    public DiffResult diff(OrderDiscount obj) {
        return new DiffBuilder(this, obj, ToStringStyle.JSON_STYLE)
                .append("bizType", this.bizType, obj.bizType)
                .append("itemId", this.itemId, obj.itemId)
                .append("discountLevel", this.discountLevel, obj.discountLevel)
                .append("discountId", this.discountId, obj.discountId)
                .append("discountType", this.discountType, obj.discountType)
                .append("discountName", this.discountName, obj.discountName)
                .append("discountSummary", this.discountSummary, obj.discountSummary)
                .append("discountAmount", this.discountAmount, obj.discountAmount)
                .append("discountText", this.discountText, obj.discountText)
                .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);
    }
}