package cn.stylefeng.team.project.api.enums;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum FilingOperateTypeEnum implements ReadableEnum<FilingOperateTypeEnum> {

    ITEM_1(1, "填报"),

    ITEM_2(2, "管理"),

    ITEM_3(3, "全部");

    @EnumValue
    @JsonValue
    private final Integer code;

    private final String message;

    FilingOperateTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static FilingOperateTypeEnum codeToEnum(String code) {
        if (null != code) {
            for (FilingOperateTypeEnum enumItem : FilingOperateTypeEnum.values()) {
                if (enumItem.getCode().toString().equals(code)) {
                    return enumItem;
                }
            }
        }
        return null;
    }

    public static String codeToMessage(String code) {
        if (null != code) {
            for (FilingOperateTypeEnum enumItem : FilingOperateTypeEnum.values()) {
                if (enumItem.getCode().toString().equals(code)) {
                    return enumItem.getMessage();
                }
            }
        }
        return "未知";
    }

    @Override
    public Object getKey() {
        return this.code;
    }

    @Override
    public Object getName() {
        return this.message;
    }

    @Override
    public FilingOperateTypeEnum parseToEnum(String originValue) {
        if (ObjectUtil.isEmpty(originValue)) {
            return null;
        }
        for (FilingOperateTypeEnum value : FilingOperateTypeEnum.values()) {
            if (value.code.toString().equals(originValue)) {
                return value;
            }
        }
        return null;
    }

}