package com.usky.vpp.enums;

import java.math.BigDecimal;
import java.util.Arrays;

/**
 * 分时时段：尖峰、高峰、平段、低谷
 */
public enum TimeSegmentEnum {

    SPIKE(1, "epp1", "epn1", new BigDecimal("1.20"), 4),
    PEAK(2, "epp2", "epn2", null, 3),
    FLAT(3, "epp3", "epn3", new BigDecimal("1.00"), 2),
    VALLEY(4, "epp4", "epn4", new BigDecimal("0.50"), 1);

    /** 账单明细 time_period：1尖 2峰 3平 4谷 */
    private final int periodCode;
    private final String forwardMetric;
    private final String reverseMetric;
    private final BigDecimal rateFactor;
    private final int priority;

    TimeSegmentEnum(int periodCode, String forwardMetric, String reverseMetric,
                    BigDecimal rateFactor, int priority) {
        this.periodCode = periodCode;
        this.forwardMetric = forwardMetric;
        this.reverseMetric = reverseMetric;
        this.rateFactor = rateFactor;
        this.priority = priority;
    }

    public int getPeriodCode() {
        return periodCode;
    }

    public String getForwardMetric() {
        return forwardMetric;
    }

    public String getReverseMetric() {
        return reverseMetric;
    }

    public BigDecimal getRateFactor() {
        return rateFactor;
    }

    public int getPriority() {
        return priority;
    }

    public static TimeSegmentEnum fromPeriodCode(int periodCode) {
        return Arrays.stream(values())
                .filter(item -> item.periodCode == periodCode)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未知时段编码：" + periodCode));
    }
}
