package com.usky.vpp.enums;

import java.time.Month;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 上海分时电价季节分类（沪发改价管〔2022〕50号）
 */
public enum ElectricSeasonEnum {

    /** 夏季：7,8,9月 */
    SUMMER(EnumSet.of(Month.JULY, Month.AUGUST, Month.SEPTEMBER)),
    /** 冬季尖峰月：1,12月 */
    WINTER_SPIKE(EnumSet.of(Month.JANUARY, Month.DECEMBER)),
    /** 普通月份：3,4,5,6,10,11月 */
    NORMAL(EnumSet.of(Month.MARCH, Month.APRIL, Month.MAY, Month.JUNE, Month.OCTOBER, Month.NOVEMBER));

    private final Set<Integer> monthNumbers;

    ElectricSeasonEnum(Set<Month> months) {
        this.monthNumbers = Collections.unmodifiableSet(months.stream()
                .map(Month::getValue)
                .collect(Collectors.toSet()));
    }

    public static ElectricSeasonEnum getByMonth(int month) {
        return Arrays.stream(values())
                .filter(season -> season.monthNumbers.contains(month))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("非法月份：" + month));
    }

    public Set<Integer> getMonthNumbers() {
        return monthNumbers;
    }
}
