package com.tofly.ghrq_route.base;

import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.common.ui.activity.UiJobList;
import com.tofly.ghrq_route.common.ui.activity.UiRepair;
import com.tofly.ghrq_route.module.emergencyHandle.ui.UiEmergencyList;
import com.tofly.ghrq_route.module.survey.ui.UiSurveyList;
import com.tofly.ghrq_route.module.trouble.domain.TroubleBean;
import com.tofly.ghrq_route.module.user.domain.UserMenuBean;
import com.tofly.ghrq_route.common.ui.activity.UiBuildManage;
import com.tofly.ghrq_route.common.ui.activity.UiMonitor;
import com.tofly.ghrq_route.common.ui.activity.UiMyTroubleList;
import com.tofly.ghrq_route.common.ui.activity.UiPhotoReportHistory;
import com.tofly.ghrq_route.common.ui.activity.UiPlan;
import com.tofly.ghrq_route.common.ui.activity.UiSign;
import com.tofly.ghrq_route.common.ui.activity.UiSketchList;
import com.tofly.ghrq_route.module.trouble.ui.UiTroubleList;
import com.tofly.ghrq_route.module.trouble.ui.UiTroubleQueryList;
import com.tofly.ghrq_route.module.trouble.ui.UiTroubleReport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainModule {
    private static MainModule mainModule = null;

    public static synchronized MainModule getInstance(){
        if (mainModule == null){
            mainModule = new MainModule();
        }
        return mainModule;
    }

    private MainModule() {
        mModuleMaps = new HashMap<>();
        initMainModule();

        mSubModuleMaps = new HashMap<>();
        mSubModuleTroubleMaps = new HashMap<>();
        mSubModuleEmergencyMaps = new HashMap<>();
        initSubModule();
    }

    /** 功能模块初始化 **/
    private final Map<String, MainModuleBean> mModuleMaps;

    /** 功能模块初始化 **/
    private final Map<String, SubModuleBean> mSubModuleMaps;

    /** 功能模块初始化 **/
    private final Map<String, SubModuleBean> mSubModuleTroubleMaps;

    /** 功能模块初始化 **/
    private final Map<String, SubModuleBean> mSubModuleEmergencyMaps;

    public Map<String, MainModuleBean> getMainModules(){
        return mModuleMaps;
    }

    public Map<String, SubModuleBean> getSubModules(){
        return mSubModuleMaps;
    }

    public Map<String, SubModuleBean> getSubTroubleModules(){
        return mSubModuleTroubleMaps;
    }

    public Map<String, SubModuleBean> getSubEmergencyModules(){
        return mSubModuleEmergencyMaps;
    }

    public void setModulesEnable(List<UserMenuBean> modules){
        if (modules != null && modules.size() > 0){
            for (UserMenuBean modulesBean : modules){
                String code = modulesBean.getCode();
                if (mModuleMaps.containsKey(code)) {
                    MainModuleBean mainModuleBean = mModuleMaps.get(code);
                    if (mainModuleBean != null)
                        mainModuleBean.setEnabled(true);
                }
            }
        }
    }

    public boolean isModuleEnabled(String code){
        boolean isEnabled = false;
        if (mModuleMaps != null){
            MainModuleBean moduleBean = mModuleMaps.get(code);
            if (moduleBean != null)
                isEnabled = moduleBean.isEnabled();
        }
        return isEnabled;
    }

    private void initMainModule(){
        for (MainModuleBean.MIAN_MODULE_INDEX moduleIndex : MainModuleBean.MIAN_MODULE_INDEX.values()){
            mModuleMaps.put(moduleIndex.getCode(), moduleIndex.getModuleBean());
        }
    }

    private void initSubModule() {
        for (SubModuleBean.SUB_MODULE_INDEX.SUB_MODULE_TROUBLE_INDEX moduleIndex : SubModuleBean.SUB_MODULE_INDEX.SUB_MODULE_TROUBLE_INDEX.values()){
            SubModuleBean.SUB_MODULE_INDEX module_index = moduleIndex.module_index;
            mSubModuleTroubleMaps.put(module_index.getCode(), module_index.getModuleBean());
        }
        mSubModuleMaps.putAll(mSubModuleTroubleMaps);


        for (SubModuleBean.SUB_MODULE_INDEX.SUB_MODULE_EMERGENCY_INDEX moduleIndex : SubModuleBean.SUB_MODULE_INDEX.SUB_MODULE_EMERGENCY_INDEX.values()){
            SubModuleBean.SUB_MODULE_INDEX module_index = moduleIndex.module_index;
            mSubModuleEmergencyMaps.put(module_index.getCode(), module_index.getModuleBean());
        }
        mSubModuleMaps.putAll(mSubModuleEmergencyMaps);
    }

    public enum MODULE_TYPE {
        MAIN_MODULE_TYPE,
        NAV_MODULE_TYPE,
        SUB_MODULE_TYPE
    }

    public static class MainModuleBean {
        private int title;
        private int image;
        private Class aclass;
        private boolean isEnabled;
        private boolean isNeedSign;  //是否需要签到
        private MODULE_TYPE module_type;

        MainModuleBean(int title, int image, Class aclass, boolean isEnabled, boolean isSign, MODULE_TYPE type){
            this.title = title;
            this.image = image;
            this.aclass = aclass;
            this.isEnabled = isEnabled;
            this.isNeedSign = isSign;
            this.module_type = type;
        }

        public int getTitle() {
            return title;
        }

        public void setTitle(int title) {
            this.title = title;
        }

        public int getImage() {
            return image;
        }

        public void setImage(int image) {
            this.image = image;
        }

        public Class getAclass() {
            return aclass;
        }

        public void setAclass(Class aclass) {
            this.aclass = aclass;
        }

        public boolean isEnabled() {
            return isEnabled;
        }

        public void setEnabled(boolean enabled) {
            isEnabled = enabled;
        }

        public boolean isNeedSign() {
            return isNeedSign;
        }

        public void setNeedSign(boolean needSign) {
            isNeedSign = needSign;
        }

        public MODULE_TYPE getModule_type() {
            return module_type;
        }

        public void setModule_type(MODULE_TYPE module_type) {
            this.module_type = module_type;
        }

        public enum MIAN_MODULE_INDEX {
//            MIAN_MODULE_DANGER("0001",      //隐患
//                    new MainModuleBean(R.string.index_gridview_danger, R.drawable.image_main_grid_danger, UiDangerReport.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_MAINTAIN_JOB("0002",   //抢维修工单
//                    new MainModuleBean(R.string.index_gridview_maintain_job, R.drawable.image_main_grid_maintain_job, UiJobList.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_BUILD("0003",       //工地
//                    new MainModuleBean(R.string.index_gridview_build_manage, R.drawable.image_main_grid_build, UiBuildManage.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_PLAN("0004",  //巡检计划
//                    new MainModuleBean(R.string.index_gridview_plan, R.drawable.image_main_grid_plan, UiPlan.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_SIGN("0005",   //上班签到
//                    new MainModuleBean(R.string.index_gridview_sign, R.drawable.image_main_grid_signup, UiSign.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_PHOTO("0006",   //照片上传
//                    new MainModuleBean(R.string.index_gridview_photo, R.drawable.image_main_grid_photo_report, UiPhotoReport.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_MY_JOB("0007",   //我的工单
//                    new MainModuleBean(R.string.index_gridview_my_job, R.drawable.image_main_grid_my_job, UiJobList.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_SKETCH("0008",   //疑问标识
//                    new MainModuleBean(R.string.index_gridview_sketch, R.drawable.image_main_grid_sketch, UiSketchList.class, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
//            MIAN_MODULE_MONITOR("0009",  //实时监控
//                    new MainModuleBean(R.string.index_gridview_monitor, R.drawable.image_main_grid_monitor, UiMonitor.class, false, MODULE_TYPE.MAIN_MODULE_TYPE));
            MIAN_MODULE_DANGER("yinhuanchuli",      //隐患
                    new MainModuleBean(R.string.index_gridview_danger, R.drawable.image_main_grid_danger, UiTroubleList.class, false, true, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_EMERGENCY_JOB("qiangweixiuguanli",   //抢维修工单
                    new MainModuleBean(R.string.index_gridview_maintain_job, R.drawable.image_main_grid_maintain_job, UiRepair.class, false, true, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_BUILD("gongdijianhuguanli",       //工地
                    new MainModuleBean(R.string.index_gridview_build_manage, R.drawable.image_main_grid_build, UiBuildManage.class, false, true, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_PLAN("xunjianjihua",  //巡检计划
                    new MainModuleBean(R.string.index_gridview_plan, R.drawable.image_main_grid_plan, UiPlan.class, false, true, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_SIGN("qiandao",   //上班签到
                    new MainModuleBean(R.string.index_gridview_sign, R.drawable.image_main_grid_signup, UiSign.class, false, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_PHOTO("zhaopianshangchuan",   //照片上传
                    new MainModuleBean(R.string.index_gridview_photo, R.drawable.image_main_grid_photo_report, UiPhotoReportHistory.class, false, true, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_MY_JOB("guanwanggongdan",   //我的工单
                    new MainModuleBean(R.string.index_gridview_my_job, R.drawable.image_main_grid_my_job, UiJobList.class, false, true, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_SKETCH("yiwenbiaozhi",   //疑问标识
                    new MainModuleBean(R.string.index_gridview_sketch, R.drawable.image_main_grid_sketch, UiSketchList.class, false, false, MODULE_TYPE.MAIN_MODULE_TYPE)),
            MIAN_MODULE_MONITOR("shishijiankong",  //实时监控
                    new MainModuleBean(R.string.index_gridview_monitor, R.drawable.image_main_grid_monitor, UiMonitor.class, false, false, MODULE_TYPE.MAIN_MODULE_TYPE));

            String code;
            MainModuleBean moduleBean;

            MIAN_MODULE_INDEX(String code, MainModuleBean moduleBean) {
                this.code = code;
                this.moduleBean = moduleBean;
            }

            public String getCode() {
                return code;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public MainModuleBean getModuleBean() {
                return moduleBean;
            }
        }
    }

    public static final int SUB_TAP_LIST_TYPE = 0;
    public static final int SUB_TOP_BUTTON_TYPE = 1;
    public static class SubModuleBean implements Comparable<SubModuleBean> {
        private int title;
        private int image;
        private int index;
        private Class aclass;
        private int select_index;
        private int sub_type;
        private String code;
        private MODULE_TYPE module_type = MODULE_TYPE.SUB_MODULE_TYPE;

        SubModuleBean(int title, int image, Class aclass, int select_index, int sub_type){
            this.title = title;
            this.image = image;
            this.aclass = aclass;
            this.select_index = select_index;
            this.sub_type = sub_type;
        }

        public int getTitle() {
            return title;
        }

        public void setTitle(int title) {
            this.title = title;
        }

        public int getImage() {
            return image;
        }

        public void setImage(int image) {
            this.image = image;
        }

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        public Class getAclass() {
            return aclass;
        }

        public void setAclass(Class aclass) {
            this.aclass = aclass;
        }

        public int getSelect_index() {
            return select_index;
        }

        public void setSelect_index(int select_index) {
            this.select_index = select_index;
        }

        public int getSub_type() {
            return sub_type;
        }

        public void setSub_type(int sub_type) {
            this.sub_type = sub_type;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public static class SUB_MODULE_INDEX {
            String code;
            int index;
            SubModuleBean moduleBean;

            SUB_MODULE_INDEX(String code, int index, SubModuleBean moduleBean) {
                this.code = code;
                this.index = index;
                this.moduleBean = moduleBean;
                this.moduleBean.code = code;
                this.moduleBean.index = index;
            }

            public String getCode() {
                return code;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public SubModuleBean getModuleBean() {
                return moduleBean;
            }

            public enum SUB_MODULE_TROUBLE_INDEX {
                SUB_MODULE_TROUBLE_TROUBLE_UPLOAD("YHSB", 0,     //隐患上报
                        new SubModuleBean(R.string.trouble_report_title, R.mipmap.trouble_upload_white,
                                UiTroubleReport.class, -1, SUB_TOP_BUTTON_TYPE)),
                SUB_MODULE_TROUBLE_MY_TROUBLE("WDYH", 1,  //我的隐患
                        new SubModuleBean(R.string.my_trouble_title, R.mipmap.my_trouble_white,
                                UiMyTroubleList.class, -1, SUB_TOP_BUTTON_TYPE)),
                SUB_MODULE_TROUBLE_QEURY_TROUBLE("YHCX", 2,  //隐患查询
                        new SubModuleBean(R.string.trouble_query_title, R.mipmap.my_trouble_white,
                                UiTroubleQueryList.class, -1, SUB_TOP_BUTTON_TYPE)),
                SUB_MODULE_TROUBLE_UNDERTAKER_ASSIGN_SCHEME_VERIFY("BZZSH", 3,  //班组长审核，编制方案，审核回执
                        new SubModuleBean(R.string.trouble_undertaker_verify, R.drawable.image_main_grid_danger,
                                UiTroubleList.class, TroubleBean.TROUBLE_SELECT_UNDERTAKER_ASSIGN_SCHEME_VERIFY, SUB_TAP_LIST_TYPE)),
                SUB_MODULE_TROUBLE_UNDERSECTARY_ASSIGN_SCHEME_VERIFY("FBZSH", 4, //副部长审核，编制方案，审核回执
                        new SubModuleBean(R.string.trouble_under_sectary_verify, R.drawable.image_main_grid_danger,
                                UiTroubleList.class, TroubleBean.TROUBLE_SELECT_UNDERSECTARY_ASSIGN_SCHEME_VERIFY, SUB_TAP_LIST_TYPE)),
                SUB_MODULE_TROUBLE_DUTY_REPORT("ZXHB", 5,  //执行回报
                        new SubModuleBean(R.string.trouble_execute_report, R.drawable.image_main_grid_danger,
                                UiTroubleList.class, TroubleBean.TROUBLE_SELECT_JOB_TAKER_EXECUTE, SUB_TAP_LIST_TYPE));

                SUB_MODULE_TROUBLE_INDEX(String code, int index, SubModuleBean moduleBean) {
                    this.module_index = new SUB_MODULE_INDEX(code, index, moduleBean);
                }

                SUB_MODULE_INDEX module_index;
            }

            public enum SUB_MODULE_EMERGENCY_INDEX {
                SUB_MODULE_EMERGENCY_QUERY_TROUBLE("YJDDCX", 0,  //应急调度查询
                        new SubModuleBean(R.string.emergency_query_title, R.mipmap.my_trouble_white,
                                UiEmergencyList.class, -1, SUB_TOP_BUTTON_TYPE)),
                SUB_MODULE_EMERGENCY_ASSIGN_HANDLE("YJDDPGCL", 1, //应急调度派工处理
                        new SubModuleBean(R.string.emergency_assign_handle_title, R.drawable.image_main_grid_danger,
                                UiEmergencyList.class, 0, SUB_TAP_LIST_TYPE)),
                SUB_MODULE_EMERGENCY_SCHEDULE_ASSIGN("DDZXQXPG", 2, //调度中心抢修派工
                        new SubModuleBean(R.string.emergency_schedule_assign_title, R.drawable.image_main_grid_danger,
                                UiEmergencyList.class, 1, SUB_TAP_LIST_TYPE)),
                SUB_MODULE_EMERGENCY_REPAIR_ASSIGN("YJDDQXPG", 3, //责任人抢修派工
                        new SubModuleBean(R.string.emergency_repair_assign_title, R.drawable.image_main_grid_danger,
                                UiEmergencyList.class, 2, SUB_TAP_LIST_TYPE)),
                SUB_MODULE_EMERGENCY_REPAIR_HANDLE("YJDDQXCL", 4, //应急调度抢修处理
                        new SubModuleBean(R.string.emergency_repair_handle_title, R.drawable.image_main_grid_danger,
                                UiEmergencyList.class, 3, SUB_TAP_LIST_TYPE));

                SUB_MODULE_EMERGENCY_INDEX(String code, int index, SubModuleBean moduleBean) {
                    this.module_index = new SUB_MODULE_INDEX(code, index, moduleBean);
                }

                SUB_MODULE_INDEX module_index;
            }
        }

        @Override
        public int compareTo(SubModuleBean t1) {
            return this.index - t1.index;
        }
    }
}
