package com.ningdatech.carapi.driver.constant;

import lombok.Getter;

import java.util.Arrays;

/**
 * <p>
 * DriverAgeRangeEnum
 * </p>
 *
 * @author WendyYang
 * @since 14:52 2022/10/27
 */
@Getter

public enum DriverAgeRangeEnum {

    /**
     * 年龄范围
     */
    AGE_20_25(20, 25, 20, "20-25岁"),
    AGE_26_30(26, 30, 26, "26-30岁"),
    AGE_31_35(31, 35, 31, "31-35岁"),
    AGE_36_40(36, 40, 36, "36-40岁"),
    AGE_41_45(41, 45, 41, "41-45岁"),
    AGE_46_50(46, 50, 46, "46-50岁"),
    AGE_51(51, -1, 51, "50岁以上");

    /**
     * 无效的值
     */
    public static final int UNDEFINED = -1;
    private final int start;
    private final int end;
    private final int key;
    private final String label;

    DriverAgeRangeEnum(int start, int end, int key, String label) {
        this.start = start;
        this.end = end;
        this.key = key;
        this.label = label;
    }

    public static DriverAgeRangeEnum getByKey(int key){
        return Arrays.stream(values())
                .filter(w -> w.getKey() == key)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的年龄编码"));
    }

}
