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 PortalAuthTypeEnum implements ReadableEnum<PortalAuthTypeEnum> {

    DESIGN("design", "拖拽布局配置"),

    CONTENT("content", "新闻、轮播图和应用链接维护"),

    ADMIN("admin", "管理员权限");

    @EnumValue
    @JsonValue
    private final String code;

    private final String message;

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

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

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

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

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

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

}