package com.unis.sxzcl.ui.work_module;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.unis.model.PermitConst;
import com.unis.model.UserModel;
import com.unis.sxzcl.R;

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

/**
 * 包名: com.unis.model
 * 类名: HomeModel
 * 作用描述: 工作台数据
 * 创建人: mQ
 * 创建时间: 2020/11/11 10:22
 * 更新人:
 * 更新时间: 2020/11/11 10:22
 * 更新说明:
 * 版本号: 1.0
 */
public class WorkbenchModel {
    private WorkbenchModel() {
    }

    private static class SingleHolder {
        private static final WorkbenchModel INSTANCE = new WorkbenchModel();
    }

    public static WorkbenchModel get() {
        return SingleHolder.INSTANCE;
    }

    public static final String TYPE_JBXX = "基本信息";
    public static final String TYPE_RYJG = "人员结构";
    public static final String TYPE_ZCZD = "政策制度";

    public static final String TYPE_SLZL = "数量质量";
    public static final String TYPE_CFXX = "仓房信息";
    public static final String TYPE_RKZL = "入库质量";
    public static final String TYPE_KCZL = "库存质量";
    public static final String TYPE_CKZL = "出库质量";


    public static final String TYPE_CLGL = "储粮管理";
    public static final String TYPE_LQJC = "粮情检查";
    public static final String TYPE_JXTF = "机械通风";
    public static final String TYPE_XZGL = "熏蒸管理";


    public static final String TYPE_YJGL = "药剂管理";
    public static final String TYPE_YJCG = "药剂采购";
    public static final String TYPE_YJBG = "药剂保管";
    public static final String TYPE_YJLY = "药剂领用";


    public static final String TYPE_SSSB = "设施设备";
    public static final String TYPE_SSGL = "设施管理";
    public static final String TYPE_SBGL = "设备管理";


    public static final String TYPE_AQSC = "安全生产";


    public static final String TYPE_JDJC = "监督检查";


    public static final String TYPE_KWGL = "库外管理";
    public static final String TYPE_ZCGL = "租仓管理";
    public static final String TYPE_WTGL = "委托管理";

    /**
     * 创建所有作业功能
     * 分一级标题 和 二级功能
     */
    public List<WorkModuleBean> createModuleList() {
        List<WorkModuleBean> list = new ArrayList<>();

        list.add(new WorkModuleBean(0, TYPE_JBXX, Arrays.asList(
                new WorkModuleBean(0, TYPE_RYJG, R.drawable.ic_model_ryjg),
                new WorkModuleBean(0, TYPE_ZCZD, R.drawable.ic_model_zczd)
        )));

        list.add(new WorkModuleBean(PermitConst.quantity, TYPE_SLZL, Arrays.asList(
                new WorkModuleBean(PermitConst.house_info, TYPE_CFXX, R.drawable.ic_model_cfxx),
//                new WorkModuleBean(TYPE_RKZL, R.drawable.ic_model_rkzl),
                new WorkModuleBean(PermitConst.quantity_quality, TYPE_KCZL, R.drawable.ic_model_kczl),
                new WorkModuleBean(PermitConst.out_quality, TYPE_CKZL, R.drawable.ic_model_ckzl)
        )));

        list.add(new WorkModuleBean(PermitConst.grain_check_manage, TYPE_CLGL, Arrays.asList(
                new WorkModuleBean(PermitConst.grain_check, TYPE_LQJC, R.drawable.ic_model_lqjc),
                new WorkModuleBean(PermitConst.aeration, TYPE_JXTF, R.drawable.ic_model_jxtf),
                new WorkModuleBean(PermitConst.fumigation, TYPE_XZGL, R.drawable.ic_model_xzgl)
        )));

        list.add(new WorkModuleBean(PermitConst.drug_manage, TYPE_YJGL, Arrays.asList(
                new WorkModuleBean(PermitConst.drug_buy, TYPE_YJCG, R.drawable.ic_model_yjcg),
                new WorkModuleBean(PermitConst.drug_custody, TYPE_YJBG, R.drawable.ic_model_yjbg),
                new WorkModuleBean(PermitConst.drug_apply, TYPE_YJLY, R.drawable.ic_model_yjly)
        )));

//        list.add(new WorkModuleBean(PermitConst.facility_device, TYPE_SSSB, Arrays.asList(
//                new WorkModuleBean(PermitConst.facility, TYPE_SSGL, R.drawable.ic_model_ssgl)
//                new WorkModuleBean(TYPE_SBGL, R.drawable.ic_model_sbgl)
//        )));

//        list.add(new WorkModuleBean(TYPE_AQSC, Arrays.asList(
//                new WorkModuleBean(TYPE_AQSC, R.drawable.ic_model_aqsc)
//        )));

//        list.add(new WorkModuleBean(TYPE_JDJC, Arrays.asList(
//                new WorkModuleBean(TYPE_JDJC, R.drawable.ic_model_jdjc)
//        )));

//        list.add(new WorkModuleBean(TYPE_KWGL, Arrays.asList(
//                new WorkModuleBean(TYPE_ZCGL, R.drawable.ic_model_zcgl),
//                new WorkModuleBean(TYPE_WTGL, R.drawable.ic_model_wtgl)
//        )));
        return list;
    }


    /**
     * 获取有权限的功能列表
     */
    public List<WorkModuleBean> getModuleList() {
        List<WorkModuleBean> list = new ArrayList<>();
        for (WorkModuleBean item : createModuleList()) {
            // 判断是否有权限
            if (UserModel.get().containPermit(item.getPermitId())) {

                List<BaseNode> childList = new ArrayList<>();
                for (BaseNode child : item.getChildNode()) {
                    WorkModuleBean childBean = (WorkModuleBean) child;
                    if (UserModel.get().containPermit(childBean.getPermitId())) {
                        childList.add(childBean);
                    }
                }

                item.setChildList(childList);

                list.add(item);
            }
        }
        return list;

    }

}