import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyEthernetSubnetDialog from "@/components/DialogComponents/EthernetSubnetDialog/CreateAndCopyEthernetSubnet.vue"
import DeleteEthernetSubnetDialog from "@/components/DialogComponents/EthernetSubnetDialog/DeleteEthernetSubnet.vue";
import UpdateEthernetSubnetDialog from '@/components/DialogComponents/EthernetSubnetDialog/UpdateEthernetSubnet.vue'

Vue.component('CreateAndCopyEthernetSubnetDialog',CreateAndCopyEthernetSubnetDialog);
Vue.component('DeleteEthernetSubnetDialog',DeleteEthernetSubnetDialog);
Vue.component('UpdateEthernetSubnetDialog',UpdateEthernetSubnetDialog);

let CommandTypes = {
  CREATE_COPY_ETHERNET_SUBNET_CMD: {
    type: 'CreateAndCopyEthernetSubnet',
    executeComponent: 'CreateAndCopyEthernetSubnetDialog',
    registerComponent: CreateAndCopyEthernetSubnetDialog
  },
  DELETE_ETHERNET_SUBNET_CMD: {
    type: 'DeleteEthernetSubnet',
    executeComponent: 'DeleteEthernetSubnetDialog',
    registerComponent: DeleteEthernetSubnetDialog // import对应的对话框组件
  },
  UPDATE_ETHERNET_SUBNET_CMD: {
    type: 'UpdateEthernetSubnet',
    executeComponent: 'UpdateEthernetSubnetDialog',
    registerComponent: UpdateEthernetSubnetDialog // import对应的对话框组件
  },
};

class EthernetSubnetCommands {
  static createAndCopyEthernetSubnetCommand (title, ethernetSubnet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_ETHERNET_SUBNET_CMD.type),
      visible: true,
      disabled: false,
      target: ethernetSubnet,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_ETHERNET_SUBNET_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.serviceSubnetAuthorityFilter(command)
  }

  static deleteEthernetSubnetCommand (ethernetSubnet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_ETHERNET_SUBNET_CMD.type),
      visible: true,
      disabled: false,
      target: ethernetSubnet,
      executeComponent: CommandTypes.DELETE_ETHERNET_SUBNET_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.serviceSubnetAuthorityFilter(command)
  }

  static updateEthernetSubnetCommand (ethernetSubnet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_ETHERNET_SUBNET_CMD.type),
      visible: true,
      disabled: false,
      target: ethernetSubnet,
      executeComponent: CommandTypes.UPDATE_ETHERNET_SUBNET_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.serviceSubnetAuthorityFilter(command)
  }
}

EthernetSubnetCommands.CommandTypes = CommandTypes;

export default EthernetSubnetCommands
