package com.zsc.edu.gateway.modules.operationLog.entity;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.zsc.edu.gateway.common.enums.IState;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author lenovo
 */
@Getter
public enum ModuleTypeEnum implements IEnum<String>, IState<ModuleTypeEnum> {
    user("user", "user"),
    role("role", "role"),
    menu("menu", "menu"),
    dept("dept", "dept"),
    device("device", "device"),
    product("product", "product"),
    serve("serve", "serve"),
    event("event", "event"),
    property("property", "property"),
    notice("notice", "notice"),
    bulletin("bulletin", "bulletin"),
    attachment("attachment", "attachment"),
    other("other", "other");

    private final String code;
    private final String messageCode;

    private static final Map<String, ModuleTypeEnum> CODE_MAP = Arrays.stream(values())
            .collect(Collectors.toMap(
                    type -> type.getCode().toLowerCase(),
                    type -> type
            ));

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

    @Override
    public String getValue() {
        return code;
    }

    @Override
    public String toString() {
        return this.messageCode;
    }

    /**
     * 根据代码获取消息
     *
     * @param code 代码
     * @return 消息
     */
    public static String getMessageByCode(String code) {
        ModuleTypeEnum type = CODE_MAP.get(code.toLowerCase());
        return Objects.requireNonNullElse(type, other).getMessageCode();
    }

}
