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.Date;
import java.util.List;

@Table(name = "wx_order_group")
@Data
public class WxOrderGroup 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;
    /**
     * 订单ID
     */
    @io.swagger.annotations.ApiModelProperty(value = "订单ID", name = "orderId")
    private Long orderId;
    /**
     * 券ID
     */
    @io.swagger.annotations.ApiModelProperty(value = "参与人ID", name = "userId")
    private Long couponId;
    /**
     * 剩余人数
     */
    @io.swagger.annotations.ApiModelProperty(value = "剩余人数", name = "remainPeople")
    private Integer remainPeople;
    /**
     * 过期时间
     */
    @io.swagger.annotations.ApiModelProperty(value = "过期时间", name = "expiredDate")
    private Date expiredDate;
    /**
     * 创建时间
     */
    @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 = "status")
    private Integer status;

    @io.swagger.annotations.ApiModelProperty(value = "用户ID", name = "userId")
    private Long userId;

    public static enum Field {
        Id_ASC("`id` ASC"), Id_DESC("`id` 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(WxOrder.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<WxOrder.Field> fList = new java.util.ArrayList();
            for (int k = 0; k < cols.length; k++) {
                fList.add(WxOrder.Field.valueOf(cols[k]));
            }
            this.setSortColumns(fList.toArray(new WxOrder.Field[fList.size()]));
        } else {
            this.setSortColumns(WxOrder.Field.valueOf(sortColumns));
        }
    }


}
