package com.njcn.supervision.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hongawen
 */

@Getter
public enum SupervisionKeyEnum {
    // 干扰源接入
    BUILD_USER_INFO("build_user_info", "user", "干扰源建档", "UserReportPOServiceImpl","supervision/interferencemanagement"),
    USER_REPORT_RENEWAL("user_report_update", "user", "干扰源常态化信息编辑", "UserReportRenewalServiceImpl","supervision/interferencemanagement"),
    USER_GO_NET("user_go_net", "user", "入网设计方案", "UserReportNormalServiceImpl","supervision/interferencemanagement"),
    USER_TREAT_CHECK("user_treat_check", "user", "治理工程验收", "UserReportNormalServiceImpl","supervision/interferencemanagement"),
    // 终端检测
    DEVICE_INFO_ADD("device_info_add", "device", "电能质量监测装置管理", "SupervisionDevMainReportPOServiceImpl","terminalNetwotk"),
    LINE_INFO_ADD("line_info_add", "device", "电能质量监测点管理", "SupervisionTempLineReportServiceImpl","terminalNetwotk"),
    TEMP_LINE_DEBUG("temp_line_debug", "device", "监测点联调", "SupervisionTempLineDebugPOServiceImpl","terminalNetwotk"),
    TIMING_CHECK_DEVICE("timing_check_device", "device", "终端周期检测", "CheckDeviceServiceImpl","terminalNetwotk"),
    // 试运行评估
    LINE_RUN_TEST("line_run_test", "device", "监测点试运行评估", "SupervisionTempLineRunTestServiceImpl","testRun"),
    // 台账管理 干扰源用户台账
    BUILD_USER_INFO_ARCHIVIST("build_user_info_archivist","user","干扰源用户台账归档","UserReportPOServiceImpl","Supervision/Terminaldetection"),
    // 技术监督计划
    SUP_PLAN_ADD("sup_plan_add", "plan", "技术监督计划流程（计划和测试）", "SupervisionPlanPOServiceImpl","supervision/harmonicmanagement"),
    SURVEY_PLAN("survey_plan", "survey", "技术监督计划", "SurveyPlanServiceImpl","supervision/harmonicmanagement"),
    SURVEY_TEST("survey_test", "survey", "技术监督测试", "SurveyTestServiceImpl","supervision/harmonicmanagement"),
    // 预告警单
    WARN_LEAFLET("warn_leaflet", "leaflet", "预/告警单", "WarningLeafletServiceImpl","supervision/supervision/manage"),
    // 终端状态管理
    QUIT_RUNNING_DEVICE("quit_running_device", "device", "终端/监测点状态变更", "QuitRunningDeviceServiceImpl","supervision/retire"),

    // 弃用
    USER_REPORT_DELETE("user_report_delete", "user", "干扰源常态化信息删除流程", "UserReportDeleteServiceImpl","");


    private final String key;

    private final String servicePrefix;

    private final String describe;

    private final String clazzName;

    private final String routePath;

    /**
     * @param key           流程标识key
     * @param servicePrefix 服务类前缀
     * @param describe      描述
     * @param clazzName     类名，方便获取spring中对应的对象
     * @param routePath     页面路由路径
     */
    SupervisionKeyEnum(String key, String servicePrefix, String describe, String clazzName, String routePath) {
        this.key = key;
        this.servicePrefix = servicePrefix;
        this.describe = describe;
        this.clazzName = clazzName;
        this.routePath = routePath;
    }

    private static final String PACKAGE_PREFIX = "com.njcn.supervision.service.";
    private static final String PACKAGE_MIDDLE = ".impl.";

    /**
     * 根据流程key获取类的全路径，用于获取spring中的对象
     */
    public static String getFullServicePathByKey(String key) {
        for (SupervisionKeyEnum supervisionKeyEnum : SupervisionKeyEnum.values()) {
            if (supervisionKeyEnum.key.equalsIgnoreCase(key)) {
                return PACKAGE_PREFIX.concat(supervisionKeyEnum.servicePrefix).concat(PACKAGE_MIDDLE).concat(supervisionKeyEnum.clazzName);
            }
        }
        return null;
    }

    /**
     * 根据流程key获取类的全路径，用于获取业务名称
     */
    public static String getBusinessNameByKey(String key) {
        for (SupervisionKeyEnum supervisionKeyEnum : SupervisionKeyEnum.values()) {
            if (supervisionKeyEnum.key.equalsIgnoreCase(key)) {
                return supervisionKeyEnum.getDescribe();
            }
        }
        return null;
    }

    /**
     * 根据流程key获取页面路由路径
     */
    public static String getRoutePathByKey(String key) {
        for (SupervisionKeyEnum supervisionKeyEnum : SupervisionKeyEnum.values()) {
            if (supervisionKeyEnum.key.equalsIgnoreCase(key)) {
                return supervisionKeyEnum.routePath;
            }
        }
        return null;
    }

    /**
     * 获取所有流程的全路径
     */
    public static List<String> getAllFullServicePath() {
        List<String> path = new ArrayList<>();
        for (SupervisionKeyEnum supervisionKeyEnum : SupervisionKeyEnum.values()) {
            path.add(PACKAGE_PREFIX.concat(supervisionKeyEnum.servicePrefix).concat(PACKAGE_MIDDLE).concat(supervisionKeyEnum.clazzName));
        }
        return path;
    }


    /**
     * 判断流程key是否在当前枚举内
     */
    public static boolean containBusinessKye(String key) {
        for (SupervisionKeyEnum supervisionKeyEnum : SupervisionKeyEnum.values()) {
            if (supervisionKeyEnum.key.equalsIgnoreCase(key)) {
                return true;
            }
        }
        return false;
    }
}
