package com.iformall.domain.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.iformall.common.SortColumn;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.domain.vo.WxCouponStatisVo;
import com.iformall.enums.EnumCouponType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;


import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

@TableName(value = "wx_coupon")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class WxCoupon extends BaseEntity {

    protected Long id;


    @TableField(exist = false)
	protected  List<Integer> types;

	@TableField(exist = false)
	protected List<Long> notinTypes;

	@TableField(exist = false)
	protected String channels;

	@TableField(exist = false)
	@SortColumn(column = "sale_price")
	private String salePriceStr;

	@TableField(exist = false)
	@SortColumn(column = "use_price")
	private String usePriceStr;

	@TableField(exist = false)
	@SortColumn(column = "price")
	private String priceStr;

	@TableField(exist = false)
	@SortColumn(column = "subsidy_num")
	private String subsidyNumStr;

	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="查询-起始时间",name="startdate")
	private Date startdate;

	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="查询-结束时间",name="enddate")
	private Date enddate;

	@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
	private String tenantId;
	@io.swagger.annotations.ApiModelProperty(value="券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券,6.多商户券,8.砍价券,9.团购券,50.积分券,51.积分停车券,100.消费卡)",name="type")
	private Integer type;
	@io.swagger.annotations.ApiModelProperty(value="封面图",name="coverImg")
	private String coverImg;
    @io.swagger.annotations.ApiModelProperty(value="多封面图",name="coverPicture")
    private String coverPicture;
    @io.swagger.annotations.ApiModelProperty(value="详情多图",name="detailPicture")
    private String detailPicture;
	@io.swagger.annotations.ApiModelProperty(value="券名称",name="title")
	private String title;
	@io.swagger.annotations.ApiModelProperty(value="副标题",name="subTitle")
	private String subTitle;

	@io.swagger.annotations.ApiModelProperty(value="售价（适用于类型2，3，4，5, 6, 8, 9, 100）",name="salePrice")
	private Integer salePrice;
	@io.swagger.annotations.ApiModelProperty(value="使用条件金额（适用于类型1,2,3,4）",name="usePrice")
	private Integer usePrice;
	@io.swagger.annotations.ApiModelProperty(value="限领张数",name="useLimitQuantity")
	private Integer useLimitQuantity;
	@io.swagger.annotations.ApiModelProperty(value="1.主动领取2.定向投放",name="sendType")
	private Integer sendType;
	@io.swagger.annotations.ApiModelProperty(value="有效时间类型1.时间范围(valid_start_date,valid_end_date). 2领取后几日有效(valid_days)",name="validType")
	private Integer validType;
	@io.swagger.annotations.ApiModelProperty(value="有效日期-开始",name="validStartDate")
	private Date validStartDate;
	@io.swagger.annotations.ApiModelProperty(value="有效日期-结束",name="validEndDate")
	private Date validEndDate;
	@io.swagger.annotations.ApiModelProperty(value="自领取之日几日有效，（停车券当天有效）",name="validDays")
	private Integer validDays;
	@io.swagger.annotations.ApiModelProperty(value="须知",name="detail")
	private String detail;
	@io.swagger.annotations.ApiModelProperty(value="面额",name="price")
	private Integer price;
	@io.swagger.annotations.ApiModelProperty(value="单位(0:rmb分 1:小时)",name="unit")
	private Integer unit;
	@io.swagger.annotations.ApiModelProperty(value="剩余库存",name="remainInventory")
	private Integer remainInventory;
	@io.swagger.annotations.ApiModelProperty(value="总库存",name="inventory")
	private Integer inventory;
	@io.swagger.annotations.ApiModelProperty(value="购买须知",name="remark")
	private String remark;
	@io.swagger.annotations.ApiModelProperty(value="状态（-1:全部,0:草稿/待生效,1:已生效,2:已失效,3:已作废）",name="status")
	private Integer status;
	@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate")
	private Date createDate;
	@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate")
	private Date updateDate;
	@io.swagger.annotations.ApiModelProperty(value="业态",name="business")
	private Integer business;
	@io.swagger.annotations.ApiModelProperty(value="子业态",name="subBusiness")
	private Integer subBusiness;
	@io.swagger.annotations.ApiModelProperty(value="是否支持转送(0:不支持,1支持)",name="supportTransfer")
	private Integer supportTransfer;

	@io.swagger.annotations.ApiModelProperty(value="过期退款(0:正常,1不退)",name="autoRefund")
	private Integer autoRefund;

	@io.swagger.annotations.ApiModelProperty(value="补贴类型(0:不支持, 1:微信支付立减与折扣, 2:线下结算, 3:微信付款到银行卡)",name="subsidyType")
	private Integer subsidyType;
	@io.swagger.annotations.ApiModelProperty(value="补贴额",name="subsidyNum")
	private Integer subsidyNum;

	@io.swagger.annotations.ApiModelProperty(value="砍价/团购限制人数",name="pressLimitNum")
	private Integer pressLimitNum;

	@io.swagger.annotations.ApiModelProperty(value="砍价限制时间",name="pressLimitHours")
	private Integer pressLimitHours;

	@io.swagger.annotations.ApiModelProperty(value="积分售价（适用于类型10,11）",name="creditPrice")
	private Integer creditPrice;

	@io.swagger.annotations.ApiModelProperty(value="过期退积分(0:正常,1不退)",name="autoRefund")
	private Integer creditRefund;

	@io.swagger.annotations.ApiModelProperty(value="领取条件",name="condition")
	private String conditions;

	@io.swagger.annotations.ApiModelProperty(value="最后一次审批操作类型,取值同EnumFlowKey",name="approvalType")
	private Integer approvalType;

	@io.swagger.annotations.ApiModelProperty(value="卡密是否支持(0:不支持,1支持)",name="passwordSupport")
	private Integer passwordSupport;

	@TableField(exist = false)
	private String merchantParams;

	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="投放频道参数,用来过滤",name="targetAd")
	private Integer targetAd;
	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="投放频道参数,用来过滤",name="couponId")
	private Long couponId;

    @TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="修改库存有效期参数, 用来做乐观锁",name="orgRemainInventory")
    private Integer orgRemainInventory;

    @TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="修改库存有效期参数, 用来做乐观锁",name="orgInventory")
    private Integer orgInventory;

	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="投放渠道id",name="couponChannelId")
	private Long couponChannelId;

	//营销分析
	@TableField(exist = false)
	@io.swagger.annotations.ApiModelProperty(value="营销分析",name="wxCouponStatisVo")
	private WxCouponStatisVo wxCouponStatisVo;

	@io.swagger.annotations.ApiModelProperty(value="投放审批状态",name="putApplyStatus")
	private Integer putApplyStatus;
	@io.swagger.annotations.ApiModelProperty(value="库存审批状态",name="stockApplyStatus")
	private Integer stockApplyStatus;
	@io.swagger.annotations.ApiModelProperty(value="作废审批状态",name="cancleApplyStatus")
	private Integer cancleApplyStatus;

	@TableField(exist = false)
	@SortColumn(column = "press_count")
	private Integer pressSendCount;
	@TableField(exist = false)
	private Integer pressCount;
	@TableField(exist = false)
	private String changeRate;
	@TableField(exist = false)
	@SortColumn(column = "join_count")
	private Integer pressJoinCount;
	@TableField(exist = false)
	private Integer paymentRate;
	@TableField(exist = false)
	private Integer saleCount;
	@TableField(exist = false)
	private Integer transferCount;
	@TableField(exist = false)
	private Integer saleAmount;
	@TableField(exist = false)
	private Integer sumPayment;
	@TableField(exist = false)
	private Integer sumSubsidy;
	@TableField(exist = false)
	private Integer backpayCount;
	@TableField(exist = false)
	private Integer pressSuccCount;

	@io.swagger.annotations.ApiModelProperty(value = "过滤可投放0不过滤 1过滤", name = "filterCanPut")
	@TableField(exist = false)
	private Integer filterCanPut;
	//审批模板id 卷、卡、拼团、砍价
	@TableField(exist = false)
	private Long couponModelId;
	@TableField(exist = false)
	private Long cardModelId;
	@TableField(exist = false)
	private Long groupModelId;
	@TableField(exist = false)
	private Long pressModelId;

	@TableField(exist = false)
	private Integer limitStart;
	@TableField(exist = false)
	private Integer limitEnd;

	@TableField(exist = false)
	@io.swagger.annotations.ApiModelProperty(value = "审批流参数", name = "flowParams")
	private Map<String, Object> flowParams;

	@io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = "isDel")
	private Integer isDel;

	public String getSalePriceStr() {
		if(salePrice!=null) {
            salePriceStr = new BigDecimal(salePrice).divide(new BigDecimal(100)).toString();
		}
		return salePriceStr;
	}

	public String getUsePriceStr() {
		if(usePrice!=null) {
			usePriceStr = new BigDecimal(usePrice).divide(new BigDecimal(100)).toString();
		}
		return usePriceStr;
	}

	public String getPriceStr() {
		if(price!=null) {
			priceStr = new BigDecimal(price).divide(new BigDecimal(100)).toString();
		}
		return priceStr;
	}

	public String getSubsidyNumStr() {
		if(subsidyNum!=null) {
			subsidyNumStr = new BigDecimal(subsidyNum).divide(new BigDecimal(100)).toString();
		}
		return subsidyNumStr;
	}

    public boolean checkIsCreditCoupon() {
	    if(type == null) {
	        return false;
        }

	    if(type == EnumCouponType.COUPON_CREDIT.getCode() ||
            type == EnumCouponType.COUPON_CREDIT_PARK.getCode()) {
	        return true;
        }
	    return false;
    }

	public boolean checkIsCard() {
		if(type == null) {
			return false;
		}

		if(type == EnumCouponType.CARD_MULTIMCH.getCode()) {
			return true;
		}
		return false;
	}

	public boolean checkIsFree() {
		if(salePrice!= null) {
			if (salePrice.equals(0)) {
				return true;
			} else {
				return false;
			}
		}
		return false;
	}

}
