import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import UpdatePerformanceMonitorDialog from '@/components/DialogComponents/PerformanceDialog/UpdatePerformanceMonitorDialog.vue'
import updatePerformanceThresholdDialog from '@/components/DialogComponents/PerformanceDialog/updatePerformanceThresholdDialog.vue'

Vue.component('UpdatePerformanceMonitorDialog',UpdatePerformanceMonitorDialog);
Vue.component('updatePerformanceThresholdDialog',updatePerformanceThresholdDialog);

let CommandTypes = {
  UPDATE_PERFORMANCE_CMD: {
    type: 'UpdatePerformanceDialog',
    executeComponent: 'UpdatePerformanceMonitorDialog',
    registerComponent: UpdatePerformanceMonitorDialog // import对应的对话框组件
  },
  UPDATE_PERFORMANCE_THE_CMD: {
    type: 'updatePerformanceThresholdDialog',
    executeComponent: 'updatePerformanceThresholdDialog',
    registerComponent: updatePerformanceThresholdDialog // import对应的对话框组件
  },
};

class PerformanceCommands {
  static updatePerformanceMonitorCommand (performance, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_PERFORMANCE_CMD.type),
      visible: true,
      disabled: false,
      target: performance,
      executeComponent: CommandTypes.UPDATE_PERFORMANCE_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.performanceConfigurationAuthorityFilter(command)
  }

  static updatePerformanceThresholdCommand (performance, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_PERFORMANCE_THE_CMD.type),
      visible: true,
      disabled: false,
      target: performance,
      executeComponent: CommandTypes.UPDATE_PERFORMANCE_THE_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.performanceThresholdrationAuthorityFilter(command)
  }

}

PerformanceCommands.CommandTypes = CommandTypes;

export default PerformanceCommands
