package jnpf.attendance.schedule;

import jnpf.model.attendance.vo.DayShiftRevenueStatVo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 智能排班「相似历史日」走营业额模型还是「按历史排班规律」模型。
 *
 * <p>当租户关闭数据分析或未上传历史营业额时，走 {@link SchedulePatternSimilarDaysAlgorithm}；
 * 配置项优先于启发式推断，见 {@link jnpf.model.attendance.vo.scheduling.ScheduleGroupRuleConfigVo}。
 */
public final class SchedulingSimilarDaysMode {

    private SchedulingSimilarDaysMode() {}

    /**
     * @param intelligentSchedulingHistoricalRevenueAvailable {@code Boolean.FALSE}
     *     强制按「无历史营业额 / 仅用排班规律」选相似日；{@code null/true} 时若历史 VO 营业额均空或 0
     *     则降级为规律模式。
     */
    public static boolean shouldUseSchedulingPatternSimilarDays(
            Boolean intelligentSchedulingHistoricalRevenueAvailable,
            List<DayShiftRevenueStatVo> dayShiftHistory) {
        if (Boolean.FALSE.equals(intelligentSchedulingHistoricalRevenueAvailable)) {
            return true;
        }
        return allHistoricalRevenueNullOrZero(dayShiftHistory);
    }

    /** 历史中无任何「非零营业额」的记录时视为无可用历史营业额样本。VO 为空也视为不可用。 */
    public static boolean allHistoricalRevenueNullOrZero(List<DayShiftRevenueStatVo> list) {
        if (list == null || list.isEmpty()) {
            return true;
        }
        for (DayShiftRevenueStatVo vo : list) {
            if (vo == null) {
                continue;
            }
            BigDecimal r = vo.getRevenue();
            if (r != null && r.signum() != 0) {
                return false;
            }
        }
        return true;
    }
}
