package com.cf.imes.module.report.enums.datasource;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author Gqr
 * @since 2024/7/17 9:43
 */
@Getter
@AllArgsConstructor
public enum ReportDatasourceTypeEnum {
    JDBC(0, "jdbc"),
    SPRING(1, "spring"),
    API(2, "api");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String desc;

    /**
     * 匹配枚举
     *
     * @param desc
     * @return
     */
    @JsonCreator
    public static ReportDatasourceTypeEnum fromDesc(String desc) {
        for (ReportDatasourceTypeEnum value : ReportDatasourceTypeEnum.values()) {
            if (value.getDesc().equals(desc)) {
                return value;
            }
        }
        return null;
    }
}
