import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateNetworkPhysicsLinkDialog from '@/components/DialogComponents/NetworkPhysicsLinkDialog/CreateNetworkPhysicsLinkDialog.vue'
import DeleteNetworkPhysicsLinkDialog from '@/components/DialogComponents/NetworkPhysicsLinkDialog/DeleteNetworkPhysicsLinkDialog.vue'
import ImportNetworkPhysicsLinkDialog from '@/components/DialogComponents/NetworkPhysicsLinkDialog/ImportNetworkPhysicsLinkDialog.vue'
import UpdateNetworkPhysicsLinkDialog from '@/components/DialogComponents/NetworkPhysicsLinkDialog/UpdateNetworkPhysicsLinkDialog.vue'

Vue.component('CreateNetworkPhysicsLinkDialog',CreateNetworkPhysicsLinkDialog);
Vue.component('DeleteNetworkPhysicsLinkDialog',DeleteNetworkPhysicsLinkDialog);
Vue.component('ImportNetworkPhysicsLinkDialog',ImportNetworkPhysicsLinkDialog);
Vue.component('UpdateNetworkPhysicsLinkDialog',UpdateNetworkPhysicsLinkDialog);
//
let CommandTypes = {
  CREATE_NETWORK_PHYSICS_LINK_CMD: {
    type: 'CreateNetworkPhysicsLink',
    executeComponent: 'CreateNetworkPhysicsLinkDialog',
    registerComponent: CreateNetworkPhysicsLinkDialog
  },
  DELETE_NETWORK_PHYSICS_LINK_CMD: {
    type: 'DeleteNetworkPhysicsLink',
    executeComponent: 'DeleteNetworkPhysicsLinkDialog',
    registerComponent: DeleteNetworkPhysicsLinkDialog
  },
  UPDATE_NETWORK_PHYSICS_LINK_CMD: {
    type: 'UpdateNetworkPhysicsLink',
    executeComponent: 'UpdateNetworkPhysicsLinkDialog',
    registerComponent: UpdateNetworkPhysicsLinkDialog
  },
  IMPORT_NETWORK_PHYSICS_LINK_CMD: {
    type: 'ImportNetworkPhysicsLink',
    executeComponent: 'ImportNetworkPhysicsLinkDialog',
    registerComponent: ImportNetworkPhysicsLinkDialog
  },
};

class NetworkPhysicsCommands {
  static createNetworkPhysicsCommand (title, netPhy, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_NETWORK_PHYSICS_LINK_CMD.type),
      visible: true,
      disabled: false,
      target: netPhy,
      title: title,
      executeComponent: CommandTypes.CREATE_NETWORK_PHYSICS_LINK_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.networkPhysicsAuthorityFilter(command)
  }

  static deleteNetworkPhysicsCommand (netPhy, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_NETWORK_PHYSICS_LINK_CMD.type),
      visible: true,
      disabled: false,
      target: netPhy,
      executeComponent: CommandTypes.DELETE_NETWORK_PHYSICS_LINK_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.networkPhysicsAuthorityFilter(command)
  }

  static updateNetworkPhysicsCommand (netPhy, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_NETWORK_PHYSICS_LINK_CMD.type),
      visible: true,
      disabled: false,
      target: netPhy,
      executeComponent: CommandTypes.UPDATE_NETWORK_PHYSICS_LINK_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.networkPhysicsAuthorityFilter(command)
  }

  static importNetworkPhysicsCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.IMPORT_NETWORK_PHYSICS_LINK_CMD.type),
      visible: true,
      disabled: false,
      target: null,
      executeComponent: CommandTypes.IMPORT_NETWORK_PHYSICS_LINK_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.networkPhysicsAuthorityFilter(command)
  }
}

NetworkPhysicsCommands.CommandTypes = CommandTypes;

export default NetworkPhysicsCommands
