package com.iformall.domain.po;

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

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

    @Id
    protected Long id;

    @Transient
    protected List<String> 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<String> getIds() {
        return ids;
    }

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

    /**
     * 渠道ID
     **/
    @io.swagger.annotations.ApiModelProperty(value = "渠道ID", name = "channelId")
    private Integer channelId;
    /**
     * 渠道名
     **/
    @io.swagger.annotations.ApiModelProperty(value = "渠道名", name = "title")
    private String title;
    /**
     * 图片url
     **/
    @io.swagger.annotations.ApiModelProperty(value = "图片url", name = "img")
    private String img;
    /**
     * 是否支持批量投放
     **/
    @io.swagger.annotations.ApiModelProperty(value = "是否支持批量投放0:不支持，1：支持", name = "batch")
    private Integer batch;

    public Integer getChannelId() {
        return channelId;
    }

    public void setChannelId(Integer _channelId) {
        channelId = _channelId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String _title) {
        title = _title;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String _img) {
        img = _img;
    }

    public Integer getBatch() {
        return batch;
    }

    public void setBatch(Integer batch) {
        this.batch = batch;
    }

    public static enum Field {
        Id_ASC("`id` ASC"), Id_DESC("`id` DESC"), ChannelId_ASC("`channel_id` ASC"), ChannelId_DESC("`channel_id` DESC"), Title_ASC("`title` ASC"), Title_DESC("`title` DESC"), Img_ASC("`img` ASC"), Img_DESC("`img` DESC"), Batch_ASC("`batch` ASC"), atch_DESC("`batch` 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(WxChannel.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));
        }
    }
}
