package com.iformall.domain.vo;

import com.iformall.domain.po.WxAuthorizerInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class WxWeappInfo extends WxAuthorizerInfo {

    @io.swagger.annotations.ApiModelProperty(value="小程序名称",name="name")
    private String name;

    public static enum Field
    {
        Id_ASC("ai.`id` ASC"),Id_DESC("ai.`id` DESC")
        ,TenantID_ASC("ai.`tenant_id` ASC"),TenantID_DESC("ai.`tenant_id` DESC")
        ,Type_ASC("ai.`type` ASC"),Type_DESC("ai.`type` DESC")
        ,AuthorizerAppid_ASC("ai.`authorizer_appid` ASC"),AuthorizerAppid_DESC("ai.`authorizer_appid` DESC")
        ,HeadImg_ASC("ai.`head_img` ASC"),HeadImg_DESC("ai.`head_img` DESC")
        ,Alias_ASC("ai.`alias` ASC"),Alias_DESC("ai.`alias` DESC")
        ,QrcodeUrl_ASC("ai.`qrcode_url` ASC"),QrcodeUrl_DESC("ai.`qrcode_url` DESC")
        ,CreateTime_ASC("ai.`create_time` ASC"),CreateTime_DESC("ai.`create_time` DESC")
        ,UpdateTime_ASC("ai.`update_time` ASC"),UpdateTime_DESC("ai.`update_time` DESC")
        ,AuthorizationStatus_ASC("ai.`authorization_status` ASC"),AuthorizationStatus_DESC("ai.`authorization_status` DESC")
        ,AuthTime_ASC("ai.`auth_time` ASC"),AuthTime_DESC("ai.`auth_time` DESC")
        ,BaseStatus_ASC("ai.`base_status` ASC"),BaseStatus_DESC("ai.`base_status` DESC")
        ,BaseTime_ASC("ai.`base_time` ASC"),BaseTime_DESC("ai.`base_time` DESC")
        ,DomainStatus_ASC("ai.`domain_status` ASC"),DomainStatus_DESC("ai.`domain_status` DESC")
        ,DomainTime_ASC("ai.`domain_time` ASC"),DomainTime_DESC("ai.`domain_time` DESC")
        ,WebDomainStatus_ASC("ai.`webdomain_status` ASC"),WebDomainStatus_DESC("ai.`webdomain_status` DESC")
        ,WebDomainTime_ASC("ai.`webdomain_time` ASC"),WebDomainTime_DESC("ai.`webdomain_time` DESC")
        ,TemplateStatus_ASC("ai.`template_status` ASC"),TemplateStatus_DESC("ai.`template_status` DESC")
        ,TemplateTime_ASC("ai.`template_time` ASC"),TemplateTime_DESC("ai.`template_time` DESC")
        ,CurrentVersion_ASC("ai.`current_version` ASC"),CurrentVersion_DESC("ai.`current_version` DESC")
        ,CurrentDesc_ASC("ai.`current_desc` ASC"),CurrentDesc_DESC("ai.`current_desc` DESC")
        ,ReleaseTime_ASC("ai.`release_time` ASC"),ReleaseTime_DESC("ai.`release_time` DESC")
        ,OpenAppid_ASC("ai.`open_appid` ASC"),OpenAppid_DESC("ai.`open_appid` DESC")
        ,BindOpenTime_ASC("ai.`bind_open_time` ASC"),BindOpenTime_DESC("ai.`bind_open_time` DESC")
        ,Name_ASC("a.`name` ASC"),Name_DESC("a.`name` 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(WxWeappInfo.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));
        }
    }
}
