package com.fizz.business.constants.enums;

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

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author chenhao
 * @date 2023/04/24
 */
@Getter
@AllArgsConstructor
public enum ExitCutTypeEnum implements IEnum<String>{
    WELDER_CUT(0), SPLIT_CUT(1);

    private final Integer code;

    private static final Map<String, ExitCutTypeEnum> MAP = new HashMap<>(5);

    static {
        for (ExitCutTypeEnum e : ExitCutTypeEnum.values()) {
            MAP.put(e.getValue(), e);
        }
    }

//    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
//    public static ExitCutTypeEnum getByValue(String value) {
//        return MAP.get(value);
//    }

//    @JsonValue
    @Override
    public String getValue() {
        return this.name();
    }

    @JsonValue
    public Integer getCode() {
        return code;
    }
    @JsonCreator
    public static ExitCutTypeEnum fromCode(int code) {
        for (ExitCutTypeEnum unit : values()) {
            if (unit.getCode() == code) {
                return unit;
            }
        }
        return null;
    }
}
