import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyEveModelDialog from "@/components/DialogComponents/ElineDialog/CreateEveModelConfigurationManagementDialog.vue"
import DeleteEveModelDialog from "@/components/DialogComponents/ElineDialog/DeleteEveModelConfigurationManagementDialog.vue";
import UpdateEveModelDialog from '@/components/DialogComponents/ElineDialog/UpdateEveModelConfigurationManagementDialog.vue'

Vue.component('CreateAndCopyEveModelDialog',CreateAndCopyEveModelDialog);
Vue.component('DeleteEveModelDialog',DeleteEveModelDialog);
Vue.component('UpdateEveModelDialog',UpdateEveModelDialog);

let CommandTypes = {
  CREATE_COPY_EVE_MODEL_CMD: {
    type: 'CreateAndCopyEveModel',
    executeComponent: 'CreateAndCopyEveModelDialog',
    registerComponent: CreateAndCopyEveModelDialog
  },
  DELETE_EVE_MODEL_CMD: {
    type: 'DeleteEveModel',
    executeComponent: 'DeleteEveModelDialog',
    registerComponent: DeleteEveModelDialog // import对应的对话框组件
  },
  UPDATE_EVE_MODEL_CMD: {
    type: 'UpdateEveModel',
    executeComponent: 'UpdateEveModelDialog',
    registerComponent: UpdateEveModelDialog // import对应的对话框组件
  },
};

class EveModelCommands {
  static createAndCopyEveModelCommand (title, eveModel, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_EVE_MODEL_CMD.type),
      visible: true,
      disabled: false,
      target: eveModel,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_EVE_MODEL_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.serviceTemplateAuthorityFilter(command)
  }

  static deleteEveModelCommand (eveModel, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_EVE_MODEL_CMD.type),
      visible: true,
      disabled: false,
      target: eveModel,
      executeComponent: CommandTypes.DELETE_EVE_MODEL_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.serviceTemplateAuthorityFilter(command)
  }

  static updateEveModelCommand (eveModel, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_EVE_MODEL_CMD.type),
      visible: true,
      disabled: false,
      target: eveModel,
      executeComponent: CommandTypes.UPDATE_EVE_MODEL_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.serviceTemplateAuthorityFilter(command)
  }
}

EveModelCommands.CommandTypes = CommandTypes;

export default EveModelCommands