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

import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.ruoyi.common.exception.ServiceException;

/**
 * 填报月份选项与年月合法性校验
 */
public final class YakHerdInventoryMonthSupport
{
    public static final int MIN_MONTH = 1;

    public static final int MAX_MONTH = 12;

    private YakHerdInventoryMonthSupport()
    {
    }

    public static List<Integer> resolveMonthOptions()
    {
        List<Integer> months = new ArrayList<>();
        for (int m = MIN_MONTH; m <= MAX_MONTH; m++)
        {
            months.add(m);
        }
        return Collections.unmodifiableList(months);
    }

    public static boolean isValidMonth(Integer statMonth)
    {
        return statMonth != null && statMonth >= MIN_MONTH && statMonth <= MAX_MONTH;
    }

    /**
     * 校验填报年月：年份在可选范围内、月份 1–12、不可填报未来月份。
     */
    public static void validateStatPeriod(Integer statYear, Integer statMonth)
    {
        if (statYear == null)
        {
            throw new ServiceException("所属年份不能为空");
        }
        if (!YakHerdInventoryYearSupport.isAllowedYear(statYear))
        {
            throw new ServiceException("所属年份不在可选范围内");
        }
        if (!isValidMonth(statMonth))
        {
            throw new ServiceException("所属月份不合法");
        }
        YearMonth selected = YearMonth.of(statYear, statMonth);
        if (selected.isAfter(YearMonth.now()))
        {
            throw new ServiceException("不能填报未来月份");
        }
    }
}
