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

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;

/**
 * 年度报告查询参数校验。
 */
public final class AchievementReportValidation
{
    private static final int MIN_YEAR = 1900;

    private static final int MAX_YEAR = 2100;

    private AchievementReportValidation()
    {
    }

    public static int parseStatYear(String statYear)
    {
        if (StringUtils.isEmpty(statYear))
        {
            throw new ServiceException("统计年份不能为空");
        }
        String trimmed = statYear.trim();
        if (!trimmed.matches("^\\d{4}$"))
        {
            throw new ServiceException("统计年份须为4位数字（如2026）");
        }
        int year = Integer.parseInt(trimmed);
        if (year < MIN_YEAR || year > MAX_YEAR)
        {
            throw new ServiceException("统计年份须在" + MIN_YEAR + "～" + MAX_YEAR + "之间");
        }
        return year;
    }
}
