import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAlarmFilterDialog from '@/components/DialogComponents/AlarmFilterDialog/CreateAlarmFilterDialog.vue'
import DeleteAlarmFilterDialog from '@/components/DialogComponents/AlarmFilterDialog/DeleteAlarmFilterDialog.vue'
import UpdateAlarmFilterDialog from '@/components/DialogComponents/AlarmFilterDialog/UpdateAlarmFilterDialog.vue'
import CopyAlarmFilterDialog from '@/components/DialogComponents/AlarmFilterDialog/CopyAlarmFilterDialog.vue'

Vue.component('CreateAlarmFilterDialog', CreateAlarmFilterDialog)
Vue.component('DeleteAlarmFilterDialog', DeleteAlarmFilterDialog)
Vue.component('UpdateAlarmFilterDialog', UpdateAlarmFilterDialog)
Vue.component('CopyAlarmFilterDialog', CopyAlarmFilterDialog)

let CommandTypes = {
  CREATE_ALARM_FILTER_CMD: {
    type: 'CreateAlarmFilter',
    executeComponent: 'CreateAlarmFilterDialog',
    registerComponent: CreateAlarmFilterDialog
  },
  DELETE_ALARM_FILTER_CMD: {
    type: 'DeleteAlarmFilter',
    executeComponent: 'DeleteAlarmFilterDialog',
    registerComponent: DeleteAlarmFilterDialog // import对应的对话框组件
  },
  UPDATE_ALARM_FILTER_CMD: {
    type: 'UpdateAlarmFilter',
    executeComponent: 'UpdateAlarmFilterDialog',
    registerComponent: UpdateAlarmFilterDialog // import对应的对话框组件
  },
  COPY_ALARM_FILTER_CMD: {
    type: 'CopyAlarmFilter',
    executeComponent: 'CopyAlarmFilterDialog',
    registerComponent: CopyAlarmFilterDialog // import对应的对话框组件
  }
}

class AlarmCommands {
  static createAlarmFilterCommand (alarmFilter, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_ALARM_FILTER_CMD.type),
      visible: true,
      disabled: false,
      target: alarmFilter,
      executeComponent: CommandTypes.CREATE_ALARM_FILTER_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.faultFilteringAuthorityFilter(command)
  }

  static deleteAlarmFilterCommand (alarmFilter, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_ALARM_FILTER_CMD.type),
      visible: true,
      disabled: false,
      target: alarmFilter,
      executeComponent: CommandTypes.DELETE_ALARM_FILTER_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.faultFilteringAuthorityFilter(command)
  }

  static updateAlarmFilterCommand (alarmFilter, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_ALARM_FILTER_CMD.type),
      visible: true,
      disabled: false,
      target: alarmFilter,
      executeComponent: CommandTypes.UPDATE_ALARM_FILTER_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.faultFilteringAuthorityFilter(command)
  }
  static copyAlarmFilterCommand (alarmFilter, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.COPY_ALARM_FILTER_CMD.type),
      visible: true,
      disabled: false,
      target: alarmFilter,
      executeComponent: CommandTypes.COPY_ALARM_FILTER_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.faultFilteringAuthorityFilter(command)
  }
}

AlarmCommands.CommandTypes = CommandTypes

export default AlarmCommands
