package com.iformall.domain.po;

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

@Table(name = "wx_screen_ad")
public class WxScreenAd 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;
	}

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

	/**标题**/
	@io.swagger.annotations.ApiModelProperty(value="标题",name="title")
	private String title;

	/**广告类型**/
	@io.swagger.annotations.ApiModelProperty(value="广告类型",name="type")
	private Integer type;

	/**广告子类型 (券渠道)**/
	@io.swagger.annotations.ApiModelProperty(value="广告子类型",name="subType")
	private Integer subType;

	/**广告状态**/
	@io.swagger.annotations.ApiModelProperty(value="设备状态",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="coverImg")
	private String coverImg;

	/**广告目标ID: couponChannelId or campaignId**/
	@io.swagger.annotations.ApiModelProperty(value="广告目标ID",name="targetId")
	private Long targetId;

	/**广告目标二维码**/
	@io.swagger.annotations.ApiModelProperty(value="二维码",name="qrcode")
	private byte[] qrcode;

	@Transient
	protected Object target;

	public String getTenantId() {
		return tenantId;
	}

	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Integer getSubType() {
		return subType;
	}

	public void setSubType(Integer subType) {
		this.subType = subType;
	}

	public Integer getStatus() {
		return status;
	}

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

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getCoverImg() {
		return coverImg;
	}

	public void setCoverImg(String coverImg) {
		this.coverImg = coverImg;
	}

	public Object getTarget() {
		return target;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	public Long getTargetId() {
		return targetId;
	}

	public void setTargetId(Long targetId) {
		this.targetId = targetId;
	}

	public byte[] getQrcode() {
		return qrcode;
	}

	public void setQrcode(byte[] qrcode) {
		this.qrcode = qrcode;
	}

	public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
			,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
			,Type_ASC("`type` ASC"),Type_DESC("`type` DESC")
			,SubType_ASC("`sub_type` ASC"),SubType_DESC("`sub_type` 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(WxScreenAd.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(",");
			List<Field> fList = new 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));
		}
	}
}
