import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyELineDialog from "@/components/DialogComponents/ElineDialog/CreateEthernetELineServiceConfigurationManagementDialog.vue"
import DeleteELineDialog from "@/components/DialogComponents/ElineDialog/DeleteEthernetELineServiceConfigurationManagementDialog.vue";
import UpdateELineDialog from '@/components/DialogComponents/ElineDialog/UpdateEthernetELineServiceConfigurationManagementDialog.vue'
import SelectELineTemplateDialog from '@/components/DialogComponents/ElineDialog/SelectElineTemplateDialog.vue'

Vue.component('CreateAndCopyELineDialog',CreateAndCopyELineDialog);
Vue.component('DeleteELineDialog',DeleteELineDialog);
Vue.component('UpdateELineDialog',UpdateELineDialog);
Vue.component('SelectELineTemplateDialog',SelectELineTemplateDialog);

let CommandTypes = {
  CREATE_COPY_ELINE_CMD: {
    type: 'CreateAndCopyELine',
    executeComponent: 'CreateAndCopyELineDialog',
    registerComponent: CreateAndCopyELineDialog
  },
  DELETE_ELINE_CMD: {
    type: 'DeleteELine',
    executeComponent: 'DeleteELineDialog',
    registerComponent: DeleteELineDialog // import对应的对话框组件
  },
  UPDATE_ELINE_CMD: {
    type: 'UpdateELine',
    executeComponent: 'UpdateELineDialog',
    registerComponent: UpdateELineDialog // import对应的对话框组件
  },
  IMPORT_ELINE_CMD: {
    type: 'SelectELineTemplate',
    executeComponent: 'SelectELineTemplateDialog',
    registerComponent: SelectELineTemplateDialog // import对应的对话框组件
  },
};

class ELineCommands {
  static createAndCopyELineCommand (title, eLine, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_ELINE_CMD.type),
      visible: true,
      disabled: false,
      target: eLine,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_ELINE_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.elineServiceAuthorityFilter(command)
  }

  static deleteELineCommand (eLine, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_ELINE_CMD.type),
      visible: true,
      disabled: false,
      target: eLine,
      executeComponent: CommandTypes.DELETE_ELINE_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.elineServiceAuthorityFilter(command)
  }

  static updateELineCommand (eLine, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_ELINE_CMD.type),
      visible: true,
      disabled: false,
      target: eLine,
      executeComponent: CommandTypes.UPDATE_ELINE_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.elineServiceAuthorityFilter(command)
  }

  static SelectELineTemplateCommand (eLine, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.IMPORT_ELINE_CMD.type),
      visible: true,
      disabled: false,
      target: eLine,
      executeComponent: CommandTypes.IMPORT_ELINE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return command
  }
}

ELineCommands.CommandTypes = CommandTypes;

export default ELineCommands
