import Vue from 'vue'
import store from '@/store'
import DataDict from '@/utils/dict'
import {getDicts as getDicts} from '@/api/system/dict/data'
let dictDataMap =
  {
    // 系统开关
    "sys_normal_disable": [
      {
        "createBy": "admin",
        "createTime": "2023-04-23 16:13:26",
        "updateBy": null,
        "updateTime": null,
        "remark": "正常状态",
        "dictCode": 6,
        "dictSort": 1,
        "dictLabel": "正常",
        "dictValue": "0",
        "dictType": "sys_normal_disable",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "Y",
        "status": "0",
        "default": true
      },
      {
        "createBy": "admin",
        "createTime": "2023-04-23 16:13:26",
        "updateBy": null,
        "updateTime": null,
        "remark": "停用状态",
        "dictCode": 7,
        "dictSort": 2,
        "dictLabel": "停用",
        "dictValue": "1",
        "dictType": "sys_normal_disable",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "default": false
      }
    ],
    // 用户性别
    "sys_user_sex": [
      {
        "createBy": "admin",
        "createTime": "2023-04-23 16:13:24",
        "updateBy": null,
        "updateTime": null,
        "remark": "性别男",
        "dictCode": 1,
        "dictSort": 1,
        "dictLabel": "男",
        "dictValue": "0",
        "dictType": "sys_user_sex",
        "cssClass": "",
        "listClass": "",
        "isDefault": "Y",
        "status": "0",
        "default": true
      },
      {
        "createBy": "admin",
        "createTime": "2023-04-23 16:13:24",
        "updateBy": null,
        "updateTime": null,
        "remark": "性别女",
        "dictCode": 2,
        "dictSort": 2,
        "dictLabel": "女",
        "dictValue": "1",
        "dictType": "sys_user_sex",
        "cssClass": "",
        "listClass": "",
        "isDefault": "N",
        "status": "0",
        "default": false
      },
      {
        "createBy": "admin",
        "createTime": "2023-04-23 16:13:25",
        "updateBy": null,
        "updateTime": null,
        "remark": "性别未知",
        "dictCode": 3,
        "dictSort": 3,
        "dictLabel": "未知",
        "dictValue": "2",
        "dictType": "sys_user_sex",
        "cssClass": "",
        "listClass": "",
        "isDefault": "N",
        "status": "0",
        "default": false
      }
    ],
    // 是否展示
    "sys_show_hide": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 4,
        "dictSort": 1,
        "dictLabel": "显示",
        "dictValue": "0",
        "dictType": "sys_show_hide",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "Y",
        "status": "0",
        "remark": "显示菜单"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 5,
        "dictSort": 2,
        "dictLabel": "隐藏",
        "dictValue": "1",
        "dictType": "sys_show_hide",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "隐藏菜单"
      }
    ],
    // 系统是否
    "sys_yes_no": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 12,
        "dictSort": 1,
        "dictLabel": "是",
        "dictValue": "Y",
        "dictType": "sys_yes_no",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "Y",
        "status": "0",
        "remark": "系统默认是"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 13,
        "dictSort": 2,
        "dictLabel": "否",
        "dictValue": "N",
        "dictType": "sys_yes_no",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "系统默认否"
      }
    ],
    // 公告类型
    "sys_notice_type": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 14,
        "dictSort": 1,
        "dictLabel": "通知",
        "dictValue": "1",
        "dictType": "sys_notice_type",
        "cssClass": "",
        "listClass": "warning",
        "isDefault": "Y",
        "status": "0",
        "remark": "通知"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 15,
        "dictSort": 2,
        "dictLabel": "公告",
        "dictValue": "2",
        "dictType": "sys_notice_type",
        "cssClass": "",
        "listClass": "success",
        "isDefault": "N",
        "status": "0",
        "remark": "公告"
      }
    ],
    // 通知状态
    "sys_notice_status": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 16,
        "dictSort": 1,
        "dictLabel": "正常",
        "dictValue": "0",
        "dictType": "sys_notice_status",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "Y",
        "status": "0",
        "remark": "正常状态"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 17,
        "dictSort": 2,
        "dictLabel": "关闭",
        "dictValue": "1",
        "dictType": "sys_notice_status",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "关闭状态"
      }
    ],
    // 系统状态
    "sys_common_status": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 28,
        "dictSort": 1,
        "dictLabel": "成功",
        "dictValue": "0",
        "dictType": "sys_common_status",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "N",
        "status": "0",
        "remark": "正常状态"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 29,
        "dictSort": 2,
        "dictLabel": "失败",
        "dictValue": "1",
        "dictType": "sys_common_status",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "停用状态"
      }
    ],
    // 定时任务组
    "sys_job_group": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 10,
        "dictSort": 1,
        "dictLabel": "默认",
        "dictValue": "DEFAULT",
        "dictType": "sys_job_group",
        "cssClass": "",
        "listClass": "",
        "isDefault": "Y",
        "status": "0",
        "remark": "默认分组"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 11,
        "dictSort": 2,
        "dictLabel": "系统",
        "dictValue": "SYSTEM",
        "dictType": "sys_job_group",
        "cssClass": "",
        "listClass": "",
        "isDefault": "N",
        "status": "0",
        "remark": "系统分组"
      }
    ],
    // 定时任务状态
    "sys_job_status": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 8,
        "dictSort": 1,
        "dictLabel": "正常",
        "dictValue": "0",
        "dictType": "sys_job_status",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "Y",
        "status": "0",
        "remark": "正常状态"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 9,
        "dictSort": 2,
        "dictLabel": "暂停",
        "dictValue": "1",
        "dictType": "sys_job_status",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "停用状态"
      }
    ],
    // 操作类型
    "sys_oper_type": [
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 19,
        "dictSort": 1,
        "dictLabel": "新增",
        "dictValue": "1",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "info",
        "isDefault": "N",
        "status": "0",
        "remark": "新增操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 20,
        "dictSort": 2,
        "dictLabel": "修改",
        "dictValue": "2",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "info",
        "isDefault": "N",
        "status": "0",
        "remark": "修改操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 21,
        "dictSort": 3,
        "dictLabel": "删除",
        "dictValue": "3",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "删除操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 22,
        "dictSort": 4,
        "dictLabel": "授权",
        "dictValue": "4",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "primary",
        "isDefault": "N",
        "status": "0",
        "remark": "授权操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 23,
        "dictSort": 5,
        "dictLabel": "导出",
        "dictValue": "5",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "warning",
        "isDefault": "N",
        "status": "0",
        "remark": "导出操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 24,
        "dictSort": 6,
        "dictLabel": "导入",
        "dictValue": "6",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "warning",
        "isDefault": "N",
        "status": "0",
        "remark": "导入操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 25,
        "dictSort": 7,
        "dictLabel": "强退",
        "dictValue": "7",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "强退操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 26,
        "dictSort": 8,
        "dictLabel": "生成代码",
        "dictValue": "8",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "warning",
        "isDefault": "N",
        "status": "0",
        "remark": "生成操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 27,
        "dictSort": 9,
        "dictLabel": "清空数据",
        "dictValue": "9",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": "清空操作"
      },
      {
        "createBy": 1,
        "createTime": "2023-09-29 11:47:28",
        "updateBy": null,
        "updateTime": null,
        "params": {
          "@type": "java.util.HashMap"
        },
        "dictCode": 18,
        "dictSort": 99,
        "dictLabel": "其他",
        "dictValue": "0",
        "dictType": "sys_oper_type",
        "cssClass": "",
        "listClass": "info",
        "isDefault": "N",
        "status": "0",
        "remark": "其他操作"
      }
    ],
    // 规则类型
    "rule_engine_type": [
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:40:51",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 30,
        "dictSort": 0,
        "dictLabel": "规则模板",
        "dictValue": "rule-template",
        "dictType": "rule_engine_type",
        "cssClass": null,
        "listClass": "primary",
        "isDefault": "N",
        "status": "0",
        "remark": null
      },
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:41:25",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 31,
        "dictSort": 1,
        "dictLabel": "自定义规则",
        "dictValue": "rule-custom",
        "dictType": "rule_engine_type",
        "cssClass": null,
        "listClass": "success",
        "isDefault": "N",
        "status": "0",
        "remark": null
      }
    ],
    // 规则作用域
    "rule_engine_level": [
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:40:51",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 30,
        "dictSort": 0,
        "dictLabel": "数据集",
        "dictValue": "data-set",
        "dictType": "rule_engine_level",
        "cssClass": null,
        "listClass": "primary",
        "isDefault": "N",
        "status": "0",
        "remark": null
      },
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:41:25",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 31,
        "dictSort": 1,
        "dictLabel": "记录",
        "dictValue": "data-record",
        "dictType": "rule_engine_level",
        "cssClass": null,
        "listClass": "primary",
        "isDefault": "N",
        "status": "0",
        "remark": null
      },
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:41:25",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 31,
        "dictSort": 1,
        "dictLabel": "数据字段",
        "dictValue": "data-field",
        "dictType": "rule_engine_level",
        "cssClass": null,
        "listClass": "primary",
        "isDefault": "N",
        "status": "0",
        "remark": null
      }
    ],
    // 规则引擎激活状态
    "rule_engine_activate_status": [
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:45:07",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 32,
        "dictSort": 0,
        "dictLabel": "未激活",
        "dictValue": "no-activate",
        "dictType": "rule_engine_activate_status",
        "cssClass": null,
        "listClass": "danger",
        "isDefault": "N",
        "status": "0",
        "remark": null
      },
      {
        "createBy": 1,
        "createTime": "2024-04-23 09:45:32",
        "updateBy": null,
        "updateTime": null,
        "dictCode": 33,
        "dictSort": 0,
        "dictLabel": "已激活",
        "dictValue": "activated",
        "dictType": "rule_engine_activate_status",
        "cssClass": null,
        "listClass": "success",
        "isDefault": "N",
        "status": "0",
        "remark": null
      }
    ]
  }
/**
 *
 * @returns {Promise<unknown>}
 */
function install() {
  Vue.use(DataDict, {
    metas: {
      '*': {
        labelField: 'dictLabel',
        valueField: 'dictValue',
        request(dictMeta) {
          let dictData = dictDataMap[dictMeta.type];
          if (dictData) {
            return new Promise(resolve => {
              resolve(dictData)
            })
          } else {
            return new Promise((resolve, reject) => {
              getDicts(dictMeta.type).then(res => {
                store.dispatch('dict/setDict', {key: dictMeta.type, value: res.data})
                resolve(res.data)
              }).catch(error => {
                reject(error)
              })
            })
          }
        },
      },
    },
  })
}

export default {
  install,
}
