package cn.stylefeng.team.portal.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 SlideshowRedirectTypeEnum implements ReadableEnum<SlideshowRedirectTypeEnum> {

    ITEM_5(5, "无跳转"),

    ITEM_10(10, "跳转到新闻"),

    ITEM_20(20, "跳转到指定URL");

    @EnumValue
    @JsonValue
    private final Integer code;

    private final String message;

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

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

    public static String codeToMessage(String code) {
        if (null != code) {
            for (SlideshowRedirectTypeEnum enumItem : SlideshowRedirectTypeEnum.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 SlideshowRedirectTypeEnum parseToEnum(String originValue) {
        if (ObjectUtil.isEmpty(originValue)) {
            return null;
        }
        for (SlideshowRedirectTypeEnum value : SlideshowRedirectTypeEnum.values()) {
            if (value.code.toString().equals(originValue)) {
                return value;
            }
        }
        return null;
    }

}