package com.iformall.domain.po;

import com.iformall.enums.EnumCouponType;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Table(name = "wx_coupon_channel")
public class WxCouponChannel implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	protected Long id;

	@Transient
	protected List<Long> ids;

	@Transient
	protected String sortColumns;

	public Long getId() {
		return id;
	}

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

	public String getSortColumns() {
		return sortColumns;
	}

	public List<Long> getIds() {
		return ids;
	}

	public void setIds(List<Long> ids) {
		this.ids = ids;
	}

	@Transient
	private Date startdate;

	@Transient
	private Date enddate;

    @Transient
    private Integer supportTransfer;

	@Transient
	protected List<Long> couponIds;

	public List<Long> getCouponIds() {
		return couponIds;
	}
	public void setCouponIds(List<Long> couponIds) {
		this.couponIds = couponIds;
	}

	/*租户ID**/
	@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
	private String tenantId;
	/*卡券id**/
	@io.swagger.annotations.ApiModelProperty(value="卡券id",name="couponId")
	private Long couponId;

	/*券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)**/
	@io.swagger.annotations.ApiModelProperty(value="券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)",name="type")
	private Integer type;
	/*券名称**/
	@io.swagger.annotations.ApiModelProperty(value="券名称",name="title")
	private String title;
	/*投放频道位置（1.列表, 2.限时抢购）**/
	@io.swagger.annotations.ApiModelProperty(value="投放频道位置（1.列表, 2.限时抢购）",name="targetAd")
	private Integer targetAd;
	/***/
	@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="开始时间",name="beginTime")
	private Date beginTime;
	/*结束时间**/
	@io.swagger.annotations.ApiModelProperty(value="结束时间",name="endTime")
	private Date endTime;
	/*0:上架 1:下架**/
	@io.swagger.annotations.ApiModelProperty(value="0:上架 1:下架",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="子频道ID",name="subTargetId")
	private Long subTargetId;

    @Transient
    @io.swagger.annotations.ApiModelProperty(value = "小程序路径", name = "weaAppPath")
    private String weaAppPath;

    @Transient
    @io.swagger.annotations.ApiModelProperty(value = "小程序二维码scene", name = "weaAppScene")
    private String weaAppScene;

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


	public String  getTenantId() {
		return tenantId;
	}
	public void setTenantId(String _tenantId) {
		tenantId = _tenantId;
	}
	public Long  getCouponId() {
		return couponId;
	}
	public void setCouponId(Long _couponId) {
		couponId = _couponId;
	}
	public Integer  getType() {
		return type;
	}
	public void setType(Integer _type) {
		type = _type;
	}
	public String  getTitle() {
		return title;
	}
	public void setTitle(String _title) {
		title = _title;
	}
	public Integer  getTargetAd() {
		return targetAd;
	}
	public void setTargetAd(Integer _targetAd) {
		targetAd = _targetAd;
	}
	public Integer  getBusiness() {
		return business;
	}
	public void setBusiness(Integer _business) {
		business = _business;
	}

	public Integer getSubBusiness() {
		return subBusiness;
	}

	public void setSubBusiness(Integer subBusiness) {
		this.subBusiness = subBusiness;
	}

	public Date  getBeginTime() {
		return beginTime;
	}
	public void setBeginTime(Date _beginTime) {
		beginTime = _beginTime;
	}
	public Date  getEndTime() {
		return endTime;
	}
	public void setEndTime(Date _endTime) {
		endTime = _endTime;
	}
	public Integer  getStatus() {
		return status;
	}
	public void setStatus(Integer _status) {
		status = _status;
	}
	public Date  getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date _createDate) {
		createDate = _createDate;
	}
	public Date  getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date _updateDate) {
		updateDate = _updateDate;
	}


	public Long getSubTargetId() {
		return subTargetId;
	}
	public void setSubTargetId(Long subTargetId) {
		this.subTargetId = subTargetId;
	}

	public Date getStartdate() {
		return startdate;
	}

	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}

	public Date getEnddate() {
		return enddate;
	}

	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}

    public Integer getSupportTransfer() {
        return supportTransfer;
    }

    public void setSupportTransfer(Integer supportTransfer) {
        this.supportTransfer = supportTransfer;
    }

	public Integer getCreditPrice() {
		return creditPrice;
	}

	public void setCreditPrice(Integer creditPrice) {
		this.creditPrice = creditPrice;
	}

	public String getWeaAppPath() {
	    if(type == null)
	        return "pages/index/index";
        if(!type.equals(EnumCouponType.COUPON_GROUP.getCode())) {
            return "pages/index/index?type=cd&couponChannelId=" + id;
        } else {
            return "pages/index/index?type=sd&couponChannelId=" + id;
        }
    }

    public String getWeaAppScene() {
        if(type == null)
            return "";
        if(!type.equals(EnumCouponType.COUPON_GROUP.getCode())) {
            return "t:cd:" + id;
        } else {
            return "t:sd:" + id;
        }
    }

    public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
		,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
		,MerchantId_ASC("`merchant_id` ASC"),MerchantId_DESC("`merchant_id` DESC")
		,CouponId_ASC("`coupon_id` ASC"),CouponId_DESC("`coupon_id` DESC")
		,CouponStatus_ASC("`coupon_status` ASC"),CouponStatus_DESC("`coupon_status` DESC")
		,Type_ASC("`type` ASC"),Type_DESC("`type` DESC")
		,Title_ASC("`title` ASC"),Title_DESC("`title` DESC")
		,TargetAd_ASC("`target_ad` ASC"),TargetAd_DESC("`target_ad` DESC")
		,Business_ASC("`business` ASC"),Business_DESC("`business` DESC")
		,BeginTime_ASC("`begin_time` ASC"),BeginTime_DESC("`begin_time` DESC")
		,EndTime_ASC("`end_time` ASC"),EndTime_DESC("`end_time` DESC")
		,Status_ASC("`status` ASC"),Status_DESC("`status` DESC")
		,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC")
		,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC")
		;
		private String value;
		Field(String value){
			this.value = value;
		}
		public String getValue() {
			return value;
		}
		public void setCol(String value) {
			this.value = value;
		}
		@Override
		public String toString() {
			return this.getValue();
		}
	}

	public void setSortColumns(WxCouponChannel.Field... fields)
	{
		if (fields == null || fields.length == 0) {
			return;
		}
		for (int k = 0; k < fields.length; k++) {
			if (fields[k] == null) {
				return;
			}
		}
		StringBuilder sb = new StringBuilder(fields[0].toString());
		for (int k = 1; k < fields.length; k++) {
			sb.append(",");
			sb.append(fields[k].toString());
		}

		this.sortColumns = sb.toString();

	}

	public void setSortColumns(String sortColumns)
	{
		if (sortColumns == null || "".equals(sortColumns.trim())) {
			return;
		}
		if (sortColumns.contains(",")) {
			String[] cols = sortColumns.split(",");
			java.util.List<Field> fList = new java.util.ArrayList();
			for (int k = 0; k < cols.length; k++) {
				fList.add(Field.valueOf(cols[k]));
			}
			this.setSortColumns(fList.toArray(new Field[fList.size()]));
		} else {
			this.setSortColumns(Field.valueOf(sortColumns));
		}
	}
}
