/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.lang3.StringUtils
 */
package com.hst.framework.domain;

import com.hst.framework.domain.BaseDomain;
import org.apache.commons.lang3.StringUtils;

public final class PageDomain
extends BaseDomain {
    public static final String ASC = "asc";
    public static final String DESC = "desc";
    public static final int MIN_PAGESIZE = 1;
    public static final int MAX_PAGESIZE = 200;
    protected int pageSize = 1;
    protected int curPageNo = 1;
    protected String orderBy = null;
    protected String order = null;
    protected boolean autoCount = false;
    protected int totalPages;
    protected int curPage;
    protected int totalRecords = -1;
    protected String search;
    protected String searchField;
    protected String searchString;
    protected String searchOper;

    public String getSearchField() {
        return this.searchField;
    }

    public void setSearchField(String searchField) {
        this.searchField = searchField;
    }

    public String getSearchOper() {
        return this.searchOper;
    }

    public void setSearchOper(String searchOper) {
        this.searchOper = searchOper;
    }

    public String getSearchString() {
        return this.searchString;
    }

    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    public PageDomain() {
    }

    public String getSearch() {
        return this.search;
    }

    public void setSearch(String search) {
        this.search = search;
    }

    public PageDomain(int pageSize) {
        this.setPageSize(pageSize);
    }

    public PageDomain(int pageSize, boolean autoCount) {
        this.setPageSize(pageSize);
        this.autoCount = autoCount;
    }

    public int getCurPageNo() {
        return this.curPageNo;
    }

    public void setCurPageNo(int curPageNo) {
        this.curPageNo = curPageNo;
        if (curPageNo < 1) {
            this.curPageNo = 1;
        }
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        if (pageSize < 1) {
            this.pageSize = 1;
        } else if (pageSize > 200) {
            this.pageSize = 200;
        }
    }

    public int getStart() {
        return (this.curPageNo - 1) * this.pageSize;
    }

    public String getOrderBy() {
        return this.orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public boolean isOrderBySetted() {
        return StringUtils.isNotBlank((CharSequence)this.orderBy);
    }

    public String getOrder() {
        return this.order;
    }

    public void setOrder(String order) {
        String[] orders;
        String[] stringArray = orders = StringUtils.split((String)StringUtils.lowerCase((String)order), (char)',');
        int n = orders.length;
        int n2 = 0;
        while (n2 < n) {
            String orderStr = stringArray[n2];
            if (!StringUtils.equals((CharSequence)DESC, (CharSequence)orderStr) && !StringUtils.equals((CharSequence)ASC, (CharSequence)orderStr)) {
                throw new IllegalArgumentException("\u6392\u5e8f\u65b9\u5411" + orderStr + "\u4e0d\u662f\u5408\u6cd5\u503c");
            }
            ++n2;
        }
        this.order = StringUtils.lowerCase((String)order);
    }

    public boolean isAutoCount() {
        return this.autoCount;
    }

    public void setAutoCount(boolean autoCount) {
        this.autoCount = autoCount;
    }

    public String getOrderStr() {
        String[] orderBys;
        if (!this.isOrderBySetted()) {
            return "";
        }
        String[] orders = StringUtils.split((String)StringUtils.lowerCase((String)this.order), (char)',');
        if (orders.length > (orderBys = StringUtils.split((String)StringUtils.lowerCase((String)this.orderBy), (char)',')).length) {
            throw new IllegalArgumentException("\u6392\u5e8f\u65b9\u5411\u4e2a\u6570\u5df2\u7ecf\u8d85\u8fc7\u6392\u5e8f\u5b57\u6bb5\u7684\u4e2a\u6570\uff0c\u8bf7\u68c0\u67e5\uff01");
        }
        StringBuilder result = new StringBuilder();
        result.append(" order by ");
        int i = 0;
        while (i < orderBys.length) {
            result.append(orderBys[i]).append(" ").append(orders[i]);
            if (i != orderBys.length - 1) {
                result.append(",");
            }
            ++i;
        }
        return result.toString();
    }

    public int getTotalPages() {
        if (this.totalRecords < 0) {
            return -1;
        }
        int count = this.totalRecords / this.pageSize;
        if (this.totalRecords % this.pageSize > 0) {
            ++count;
        }
        return count;
    }

    public boolean isHasNext() {
        return this.curPageNo + 1 <= this.getTotalPages();
    }

    public int getNextPage() {
        if (this.isHasNext()) {
            return this.curPageNo + 1;
        }
        return this.curPageNo;
    }

    public boolean isHasPre() {
        return this.curPageNo - 1 >= 1;
    }

    public int getPrePage() {
        if (this.isHasPre()) {
            return this.curPageNo - 1;
        }
        return this.curPageNo;
    }

    public int getCurPage() {
        return this.getCurPageNo();
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getTotalRecords() {
        return this.totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
}
