import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import DeleteConfigDialog from '@/components/DialogComponents/ConfigDialog/DeleteConfigDialog.vue'
import downloadConfigToDeviceInConfigConfiguration from '@/components/DialogComponents/ConfigDialog/downloadConfigToDeviceInConfigConfiguration.vue'
import UpdateConfigDialog from '@/components/DialogComponents/ConfigDialog/UpdateConfigDialog.vue'
import UploadConfigFileDialog from '@/components/DialogComponents/ConfigDialog/UploadConfigFileDialog.vue'
import UploadDeviceConfigFileInConfigConfiguration from '@/components/DialogComponents/ConfigDialog/UploadDeviceConfigFileInConfigConfiguration.vue'
import LocalConfigToDevice from '@/components/DialogComponents/ConfigDialog/LocalConfigToDeviceDialog.vue'

Vue.component('DeleteConfigDialog', DeleteConfigDialog)
Vue.component('downloadConfigToDeviceInConfigConfiguration', downloadConfigToDeviceInConfigConfiguration)
Vue.component('UpdateConfigDialog', UpdateConfigDialog)
Vue.component('UploadConfigFileDialog', UploadConfigFileDialog)
Vue.component('UploadDeviceConfigFileInConfigConfiguration', UploadDeviceConfigFileInConfigConfiguration)
Vue.component('LocalConfigToDevice', LocalConfigToDevice)

let CommandTypes = {
  LOCAL_CONFIG_TO_DEVICE_CMD: {
    type: 'localConfigToDevice',
    executeComponent: 'LocalConfigToDevice',
    registerComponent: LocalConfigToDevice // 对应的对话框组件
  },
  DElETE_CONFIG__CMD: {
    type: 'DeleteConfigType',
    executeComponent: 'DeleteConfigDialog',
    registerComponent: DeleteConfigDialog // 对应的对话框组件
  },
  DOWNLOAD_CONFIG_TO_DEVICE_IN_CONFIG_CMD: {
    type: 'DownLoadConfigToDeviceInConfigType',
    executeComponent: 'downloadConfigToDeviceInConfigConfiguration',
    registerComponent: downloadConfigToDeviceInConfigConfiguration // import对应的对话框组件
  },
  UPDATE_CONFIG_CMD: {
    type: 'UpdateConfigType',
    executeComponent: 'UpdateConfigDialog',
    registerComponent: UpdateConfigDialog // import对应的对话框组件
  },
  UPLOAD_CONFIG_FILE_CMD: {
    type: 'UploadConfigFileType',
    executeComponent: 'UploadConfigFileDialog',
    registerComponent: UploadConfigFileDialog // import对应的对话框组件
  },
  UPLOAD_DEVICE_CONFIG_FILE_IN_CONFIG_CMD: {
    type: 'UploadDeviceConfigFileInConfigType',
    executeComponent: 'UploadDeviceConfigFileInConfigConfiguration',
    registerComponent: UploadDeviceConfigFileInConfigConfiguration // import对应的对话框组件
  }

}

class ConfigFileCommands {
  static deleteConfigCommand (deleteList, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DElETE_CONFIG__CMD.type),
      visible: true,
      disabled: false,
      target: deleteList,
      executeComponent: CommandTypes.DElETE_CONFIG__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.configurationFileAuthorityFilter(command)
  }

  static updateConfigCommand (updateInitList, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_CONFIG_CMD.type),
      visible: true,
      disabled: false,
      target: updateInitList,
      executeComponent: CommandTypes.UPDATE_CONFIG_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.configurationFileAuthorityFilter(command)
  }

  static downloadConfigToDeviceCommand (updateConfigFileKey, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DOWNLOAD_CONFIG_TO_DEVICE_IN_CONFIG_CMD.type),
      visible: true,
      disabled: false,
      target: updateConfigFileKey,
      executeComponent: CommandTypes.DOWNLOAD_CONFIG_TO_DEVICE_IN_CONFIG_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.configurationFileAuthorityFilter(command)
  }

  static localConfigToDeviceCommand (updateConfigFileKey, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.LOCAL_CONFIG_TO_DEVICE_CMD.type),
      visible: true,
      disabled: false,
      target: updateConfigFileKey,
      executeComponent: CommandTypes.LOCAL_CONFIG_TO_DEVICE_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.configurationFileAuthorityFilter(command)
  }

  static uploadConfigToDeviceCommand (updateConfigFileKey, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPLOAD_DEVICE_CONFIG_FILE_IN_CONFIG_CMD.type),
      visible: true,
      disabled: false,
      target: updateConfigFileKey,
      executeComponent: CommandTypes.UPLOAD_DEVICE_CONFIG_FILE_IN_CONFIG_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.configurationFileAuthorityFilter(command)
  }

  static importConfigCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPLOAD_CONFIG_FILE_CMD.type),
      visible: true,
      disabled: false,
      executeComponent: CommandTypes.UPLOAD_CONFIG_FILE_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.configurationFileAuthorityFilter(command)
  }
}

ConfigFileCommands.CommandTypes = CommandTypes

export default ConfigFileCommands