package com.ruoyi.web.modules.news.support;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.news.domain.LivestockResourceQuery;

/**
 * 畜牧资源列表查询参数规范化。
 */
public final class LivestockResourceQuerySupport
{
    private LivestockResourceQuerySupport()
    {
    }

    public static LivestockResourceQuery normalize(LivestockResourceQuery query)
    {
        LivestockResourceQuery effective = query != null ? query : new LivestockResourceQuery();
        if (StringUtils.isNotEmpty(effective.getType()))
        {
            effective.setType(effective.getType().trim());
        }
        if (StringUtils.isNotEmpty(effective.getTitle()))
        {
            effective.setTitle(effective.getTitle().trim());
        }
        effective.setPageNum(resolvePageNum(effective.getPageNum()));
        effective.setPageSize(resolvePageSize(effective.getPageSize()));
        return effective;
    }

    static int resolvePageNum(Integer pageNum)
    {
        if (pageNum == null || pageNum < 1)
        {
            return LivestockResourceRules.DEFAULT_PAGE_NUM;
        }
        return pageNum;
    }

    static int resolvePageSize(Integer pageSize)
    {
        if (pageSize == null || pageSize < 1)
        {
            return LivestockResourceRules.DEFAULT_PAGE_SIZE;
        }
        return Math.min(pageSize, LivestockResourceRules.MAX_PAGE_SIZE);
    }
}
