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

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

/**
 * 养殖资讯列表查询参数规范化。
 */
public final class FarmingNewsQuerySupport
{
    private FarmingNewsQuerySupport()
    {
    }

    public static FarmingNewsQuery normalize(FarmingNewsQuery query)
    {
        FarmingNewsQuery effective = query != null ? query : new FarmingNewsQuery();
        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 FarmingNewsRules.DEFAULT_PAGE_NUM;
        }
        return pageNum;
    }

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