import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyServiceTypeDialog from "@/components/DialogComponents/ServiceTypeDialog/CreateAndCopyServiceTypeDialog.vue"
import DeleteServiceTypeDialog from "@/components/DialogComponents/ServiceTypeDialog/DeleteServiceTypeDialog.vue";
import UpdateServiceTypeDialog from '@/components/DialogComponents/ServiceTypeDialog/UpdateServiceTypeDialog.vue'

Vue.component('CreateAndCopyServiceTypeDialog',CreateAndCopyServiceTypeDialog);
Vue.component('DeleteServiceTypeDialog',DeleteServiceTypeDialog);
Vue.component('UpdateServiceTypeDialog',UpdateServiceTypeDialog);

let CommandTypes = {
  CREATE_COPY_SERVICE_TYPE_CMD: {
    type: 'CreateAndCopyServiceType',
    executeComponent: 'CreateAndCopyServiceTypeDialog',
    registerComponent: CreateAndCopyServiceTypeDialog
  },
  DELETE_SERVICE_TYPE_CMD: {
    type: 'DeleteServiceType',
    executeComponent: 'DeleteServiceTypeDialog',
    registerComponent: DeleteServiceTypeDialog // import对应的对话框组件
  },
  UPDATE_SERVICE_TYPE_CMD: {
    type: 'UpdateServiceType',
    executeComponent: 'UpdateServiceTypeDialog',
    registerComponent: UpdateServiceTypeDialog // import对应的对话框组件
  },
};

class ServiceTypeCommands {
  static createAndCopyServiceTypeCommand (title, serviceType, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_SERVICE_TYPE_CMD.type),
      visible: true,
      disabled: false,
      target: serviceType,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_SERVICE_TYPE_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.serviceTypeAuthorityFilter(command)
  }

  static deleteServiceTypeCommand (serviceType, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_SERVICE_TYPE_CMD.type),
      visible: true,
      disabled: false,
      target: serviceType,
      executeComponent: CommandTypes.DELETE_SERVICE_TYPE_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.serviceTypeAuthorityFilter(command)
  }

  static updateServiceTypeCommand (commandContext,serviceType) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_SERVICE_TYPE_CMD.type),
      visible: true,
      disabled: false,
      target: serviceType,
      executeComponent: CommandTypes.UPDATE_SERVICE_TYPE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
    };
    console.log("456")
    console.log(command.target)
    command.execute = function () {
      command.target = serviceType
      Vue.set(commandContext, command.id, command);

      console.log("123")
      console.log(command)
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return AuthorityFilter.serviceTypeAuthorityFilter(command)
  }
}

ServiceTypeCommands.CommandTypes = CommandTypes;

export default ServiceTypeCommands
