package com.qmth.distributed.print.business.enums;

import com.qmth.boot.core.exception.StatusException;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 课程知识点编号枚举
 * @Author: CaoZixuan
 * @Date: 2022-10-18
 */
public enum CourseDimensionCodeEnum {
    A("A", 1),
    B("B", 2),
    C("C", 3),
    D("D", 4),
    E("E", 5),
    F("F", 6),
    G("G", 7),
    H("H", 8),
    I("I", 9),
    J("J", 10),
    K("K", 11),
    L("L", 12),
    M("M", 13),
    N("N", 14),
    O("O", 15),
    P("P", 16),
    Q("Q", 17),
    R("R", 18),
    S("S", 19),
    T("T", 20),
    U("U", 21),
    V("V", 22),
    W("W", 23),
    X("X", 24),
    Y("Y", 25),
    Z("Z", 26),
    a("a", 27),
    b("b", 28),
    c("c", 29),
    d("d", 30),
    e("e", 31),
    f("f", 32),
    g("g", 33),
    h("h", 34),
    i("i", 35),
    j("j", 36),
    k("k", 37),
    l("l", 38),
    m("m", 39),
    n("n", 40),
    o("o", 41),
    p("p", 42),
    q("q", 43),
    r("r", 44),
    s("s", 45),
    t("t", 46),
    u("u", 47),
    v("v", 48),
    w("w", 49),
    x("x", 50),
    y("y", 51),
    z("z", 52);

    private final String code;
    private final int index;

    CourseDimensionCodeEnum(String code, int index) {
        this.code = code;
        this.index = index;
    }

    public String getCode() {
        return code;
    }

    public int getIndex() {
        return index;
    }

    /**
     * 根据索引查找编号
     *
     * @param index 索引
     * @return 编号
     */
    public static String getCodeByIndex(int index) {
        String result = "";
        List<CourseDimensionCodeEnum> courseDimensionCodeEnumList = Arrays.stream(CourseDimensionCodeEnum.values())
                .filter(e -> index == e.getIndex())
                .collect(Collectors.toList());
        int size = courseDimensionCodeEnumList.size();
        if (size > 1) {
            throw new StatusException("index:" + index + "的编号枚举异常");
        } else if (size == 1) {
            result = courseDimensionCodeEnumList.get(0).getCode();
        }
        return result;
    }
}
