package com.sckw.core.model.enums;

import com.sckw.core.utils.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author lfdc
 * @description 项目日志枚举
 * @date 2023-11-09 09:30:07
 */
@Getter
@AllArgsConstructor
public enum MessageLogEnum {
    /**
     * 新增边坡项目
     */
    ADD_PROJECT("slope_manage", "PROJECT_LOG", "新增边坡项目", "1",
            "边坡【${projectName}】已新增，所属矿山:${mountainName}", "新增边坡项目"),
    /**
     * 修改边坡项目
     */
    UPDATE_PROJECT("slope_manage", "PROJECT_LOG", "修改边坡项目", "2",
            "边坡【${projectName}】已修改，所属矿山:${mountainName}", "修改边坡项目"),
    /**
     * 删除边坡项目
     */
    DELETE_PROJECT("slope_manage", "PROJECT_LOG", "删除边坡项目", "3",
            "边坡【${projectName}】已删除，所属矿山:${mountainName}", "删除边坡项目"),

    /**
     * 新增组网设备
     */
    ADD_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "新增组网设备", "4",
            "设备【${deviceName}】已关联组网，所属边坡【${projectName}】", "新增组网设备"),

    /**
     * 修改组网设备
     */
    UPDATE_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "修改组网设备", "28",
            "设备【${deviceName}】已修改组网，所属边坡【${projectName}】", "修改组网设备"),
    /**
     * 删除组网设备
     */
    DELETE_NETWORKING_DEVICE("slope_manage", "PROJECT_LOG", "删除组网设备", "5",
            "设备【${deviceName}】已取消组网，所属边坡【${projectName}】", "删除组网设备"),
    /**
     * 调整设备布设
     */
    UPDATE_DEVICE_LAY("slope_manage", "PROJECT_LOG", "调整设备布设", "6",
            "设备【${deviceName}】已调整项目位置，所属边坡【${projectName}】", "调整设备布设"),
    /**
     * 新增报表模版
     */
    ADD_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "新增报表模版", "7",
            "报表模版【${templateName}】已新增，所属边坡【${projectName}】", "新增报表模版"),

    /**
     * 修改报表模版
     */
    UPDATE_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "修改报表模版", "8",
            "报表模版【${templateName}】已修改，所属边坡【${projectName}】", "修改报表模版"),

    /**
     * 删除报表模版
     */
    DELETE_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "删除报表模版", "9",
            "报表模版【${templateName}】已删除，所属边坡【${projectName}】", "删除报表模版"),

    /**
     * 禁用报表模版
     */
    FORBIDDEN_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "禁用报表模版", "10",
            "报表模版【${templateName}】已禁用，所属边坡【${projectName}】", "禁用报表模版"),

    /**
     * 启用报表模版
     */
    ENABLE_REPORT_TEMPLATE("slope_manage", "PROJECT_LOG", "启用报表模版", "11",
            "报表模版【${templateName}】已启用，所属边坡【${projectName}】", "启用报表模版"),

    /**
     * 设置设备阈值
     */
    SETTINGS_DEVICE_THRESHOLD("slope_manage", "PROJECT_LOG", "设置设备阈值", "12",
            "设备【${deviceName}】已设置了【${element}】监测要素阈值，所属边坡【${projectName}】", "设置设备阈值"),

    /**
     * 删除设备阈值
     */
    DELETE_DEVICE_THRESHOLD("slope_manage", "PROJECT_LOG", "删除设备阈值", "13",
            "设备【${deviceName}】已删除了【${element}】监测要素阈值，所属边坡【${projectName}】", "删除设备阈值"),
    /**
     * 新增集成分析方案
     */
    INTEGRATION_ADD("slope_manage", "PROJECT_LOG", "新增集成分析方案", "14",
            "集成要素【${name}】已被新增，【${type}】所有设备", "新增集成分析方案"),
    /**
     * 修改集成分析方案
     */
    INTEGRATION_UPDATE("slope_manage", "PROJECT_LOG", "修改集成分析方案", "15",
            "集成要素【${name}】已被修改，【${type}】所有设备", "修改集成分析方案"),

    /**
     * 新增设备型号
     */
    MODEL_ADD("slope_manage", "PROJECT_LOG", "新增设备型号", "16",
            "型号【${name}】已被新增", "新增设备型号"),

    /**
     * 修改设备型号
     */
    MODEL_UPDATE("slope_manage", "PROJECT_LOG", "修改设备型号", "17",
            "型号【${name}】已被修改", "修改设备型号"),

    /**
     * 删除设备型号
     */
    MODEL_DELETE("slope_manage", "PROJECT_LOG", "删除设备型号", "18",
            "型号【${name}】已被删除", "删除设备型号"),
    /**
     * 新增设备
     */
    DEVICE_ADD("slope_manage", "PROJECT_LOG", "新增设备", "19",
            "设备【${name}】已被新增，所属型号【${type}】", "新增设备"),
    /**
     * 修改设备
     */
    DEVICE_UPDATE("slope_manage", "PROJECT_LOG", "修改设备", "20",
            "设备【${name}】已被修改，所属型号【${type}】", "修改设备"),
    /**
     * 删除设备
     */
    DEVICE_DELETE("slope_manage", "PROJECT_LOG", "删除设备", "21",
            "设备【${name}】已被删除，所属型号【${type}】", "删除设备"),
    /**
     * 禁用设备
     */
    DEVICE_DISABLED("slope_manage", "PROJECT_LOG", "禁用设备", "22",
            "设备【${name}】已被禁用，所属型号【${type}】", "禁用设备"),

    /**
     * 启用设备
     */
    DEVICE_ABLED("slope_manage", "PROJECT_LOG", "启用设备", "23",
            "设备【${name}】已被启用，所属型号【${type}】", "启用设备"),
    /**
     * 设备基准值设置
     */
    DEVICE_SETBASE("slope_manage", "PROJECT_LOG", "设备基准值设置", "24",
            "设备【${name}】已被设置阈值，相关要素【${type}】，所属边坡【${desc}】", "设备基准值设置"),
    /**
     * 设备基准值调整
     */
    DEVICE_SETVALUE("slope_manage", "PROJECT_LOG", "设备基准值调整", "25",
            "设备【${name}】已被调整阈值，相关要素【${type}】，所属边坡【${desc}】", "设备基准值调整"),

    /**
     * 报表批量下载
     */
    REPORT_BATCH_EXPORT("slope_manage", "PROJECT_LOG", "报表批量下载", "26",
            "共有${count}条边坡报表被批量下载，请确认", "报表批量下载"),
    /**
     * 报表批量删除
     */
    REPORT_BATCH_DELETE("slope_manage", "PROJECT_LOG", "报表批量删除", "27",
            "共有${count}条边坡报表被批量删除，请确认", "报表批量删除"),

    REFERENCE_EDIT("slope_manage", "PROJECT_LOG", "调整基准", "29",
            "设备【${name}】已调整了监测基准值,所属边坡【${projectName}】,【${desc}】", "调整基准"),

    REFERENCE_ADD("slope_manage", "PROJECT_LOG", "设置基准", "30",
            "设备【${name}】已设置了监测基准值,所属边坡【${projectName}】,【${desc}】", "设置基准"),

    COMPANY_ADD("slope_manage", "PROJECT_LOG", "新增矿山", "31",
            "新增矿山【${name}】，矿山类型：【${type}】", "新增矿山"),

    COMPANY_UPDATE("slope_manage", "PROJECT_LOG", "修改矿山", "32",
            "修改矿山【${name}】，矿山类型：【${type}】", "修改矿山"),

    ;


    /**
     * 消息分类：BUSINESS业务消息，SYSTEM系统消息
     */
    private final String category;

    /**
     * 消息类型
     */
    private final String type;

    /**
     * 消息标题
     */
    private final String title;

    /**
     * code值
     */
    private final String code;

    /**
     * 消息内容
     */
    private final String content;

    /**
     * 字段含义解释
     */
    private final String desc;


    public static String getCategoryByType(String type) {
        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
            if (entityEnum.getType().equals(type)) {
                return entityEnum.getCategory();
            }
        }
        return null;
    }

    public static String getTitleByType(String type) {
        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
            if (entityEnum.getType().equals(type)) {
                return entityEnum.getTitle();
            }
        }
        return null;
    }

    public static String getContentByType(String type) {
        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
            if (entityEnum.getType().equals(type)) {
                return entityEnum.getContent();
            }
        }
        return null;
    }

    public static String getDesc(MessageLogEnum messageEnum) {
        for (MessageLogEnum entityEnum : MessageLogEnum.values()) {
            if (entityEnum.equals(messageEnum)) {
                return entityEnum.getDesc();
            }
        }
        return null;
    }

    public static List<MessageLogEnum> getEnums(Boolean isMain, Integer length, Set<MessageLogEnum> excludeEnums) {
        List<MessageLogEnum> list = Arrays.stream(MessageLogEnum.values())
                .filter(e -> CollectionUtils.isEmpty(excludeEnums) || !excludeEnums.contains(e))
                .filter(e -> Boolean.TRUE.equals(isMain) || "BUSINESS".equals(e.getCategory()))
                .limit(length)
                .collect(Collectors.toList());
        return CollectionUtils.emptyIfNull(list);
    }

    public static MessageLogEnum getEnumByCategoryAndType(String category, String type) {
        for (MessageLogEnum e : MessageLogEnum.values()) {
            if (e.getCategory().equals(category) && e.getType().equals(type)) {
                return e;
            }
        }
        return null;
    }

    public static String getEnumTitleByCode(String code) {
        for (MessageLogEnum e : MessageLogEnum.values()) {
            if (e.getCode().equals(code)) {
                return e.title;
            }
        }
        return null;
    }
}
