package com.iformall.domain.po;

import lombok.Data;

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_weapp_release_status")
@Data
public class WxWeappReleaseStatus implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
    protected Long id;

    @Transient
    protected List<Long> ids;
    @Transient
    protected String sortColumns;

    @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
    private String tenantId;
	@io.swagger.annotations.ApiModelProperty(value="小程序ID",name="appId")
	private String appId;
	@io.swagger.annotations.ApiModelProperty(value="小程序类型(1-B端 2-C端)",name="type")
	private Integer type;
	@io.swagger.annotations.ApiModelProperty(value="用户版本",name="userVersion")
	private String userVersion;
    @io.swagger.annotations.ApiModelProperty(value="用户版本描述",name="versionDesc")
    private String versionDesc;
    @io.swagger.annotations.ApiModelProperty(value="发布状态(0:发布成功, 1:发布失败, 2:发布中, 3:发布撤回)",name="releaseStatus")
    private Integer releaseStatus;
    @io.swagger.annotations.ApiModelProperty(value="发布错误码",name="releaseErrCode")
    private String releaseErrCode;
    @io.swagger.annotations.ApiModelProperty(value="发布时间",name="releaseTime")
    private Date releaseTime;

	public static enum Field
	{
		Id_ASC("`id` ASC"),Id_DESC("`id` DESC")
            ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC")
			,AppId_ASC("`app_id` ASC"),AppId_DESC("`app_id` DESC")
			,Type_ASC("`type` ASC"),Type_DESC("`type` DESC")
			,UserVersion_ASC("`user_version` ASC"),UserVersion_DESC("`user_version` DESC")
			,ReleaseTime_ASC("`release_time` ASC"),ReleaseTime_DESC("`release_time` 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(WxWeappReleaseStatus.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));
		}
	}
}
