import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import DeleteTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/DeleteTopologicalDialog.vue'
import ImportTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/ImportTopologicalDialog.vue'
import EnableTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/EnableTopologicalDialog.vue'
import DisableTopologicalDialog from '@/components/DialogComponents/TopologicalDialog/DisableTopologicalDialog.vue'


Vue.component('DeleteTopologicalDialog', DeleteTopologicalDialog)
Vue.component('ImportTopologicalDialog', ImportTopologicalDialog)
Vue.component('EnableTopologicalDialog', EnableTopologicalDialog)
Vue.component('DisableTopologicalDialog', DisableTopologicalDialog)

let CommandTypes = {
  UPLOAD_TOPOLOGICAL__CMD: {
    type: 'UploadTopological',
    executeComponent: 'ImportTopologicalDialog',
    registerComponent: ImportTopologicalDialog // 对应的对话框组件
  },
  DElETE_TOPOLOGICAL__CMD: {
    type: 'DeleteToplological',
    executeComponent: 'DeleteTopologicalDialog',
    registerComponent: DeleteTopologicalDialog // 对应的对话框组件
  },
  ENABLE_TOPOLOGICAL__CMD: {
    type: 'EnableToplological',
    executeComponent: 'EnableTopologicalDialog',
    registerComponent: EnableTopologicalDialog // 对应的对话框组件
  },
  DISABLE_TOPOLOGICAL__CMD: {
    type: 'DisableToplological',
    executeComponent: 'DisableTopologicalDialog',
    registerComponent: DisableTopologicalDialog // 对应的对话框组件
  },
}

class TopologicalDynamicCommands {
  static uploadTopologicalCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPLOAD_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: null,
      executeComponent: CommandTypes.UPLOAD_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }

  static deleteTopologicalCommand (topoKeyList, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DElETE_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: topoKeyList,
      executeComponent: CommandTypes.DElETE_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }

  static enableTopologicalCommand (enableString, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.ENABLE_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: enableString,
      executeComponent: CommandTypes.ENABLE_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }

  static disableTopologicalCommand (disableString, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DISABLE_TOPOLOGICAL__CMD.type),
      visible: true,
      disabled: false,
      target: disableString,
      executeComponent: CommandTypes.DISABLE_TOPOLOGICAL__CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.topologicalAuthorityFilter(command)
  }
}

TopologicalDynamicCommands.CommandTypes = CommandTypes;

export default TopologicalDynamicCommands
