import uniqueId from 'lodash'
import {i18n} from '../main'

const CommandTypes = {
  // 设备
  SELECT_DEVICE_CMD: 'SelectDevice', // 设备勾选
  DESELECT_DEVICE_CMD: 'DeselectDevice', // 设备取消勾选

  // 链路
  SELECT_LINK_CMD: '', // 链路勾选
  DESELECT_LINK_CMD: '', // 链路取消勾选
}

class ElementDiscoveryCommands {
  // 选择设备
  static selectDeviceCommand(callback) {
    const command = {
      id: uniqueId(CommandTypes.SELECT_DEVICE_CMD),
      diabled: false,
      execute: () => {
        callback(true)
      },
      name: i18n.tc('ElementDiscoveryCommands.selectDevice')
    }
    return command
  }

  // 取消选择设备
  static deselectDeviceCommand(callback) {
    const command = {
      id: uniqueId(CommandTypes.DESELECT_DEVICE_CMD),
      disabled: false,
      execute: () => {
        callback(false)
      },
      name: i18n.tc('ElementDiscoveryCommands.deselectDevice')
    }
    return command
  }

  // 选择链路
  static selectLinkCommand(callback) {
    const command = {
      id: uniqueId(CommandTypes.SELECT_LINK_CMD),
      disabled: false,
      execute: () => {
        callback(true)
      },
      name: i18n.tc('ElementDiscoveryCommands.selectLink')
    }
    return command
  }

  // 取消选择链路
  static deselectLinkCommand(callback) {
    const command = {
      id: uniqueId(CommandTypes.DESELECT_LINK_CMD),
      disabled: false,
      execute: () => {
        callback(false)
      },
      name: i18n.tc('ElementDiscoveryCommands.deselectLink')
    }
    return command
  }

  // 设备右键
  static generateCommandsForDevice(callback = () => {}) {
    const cmdList = []
    // 选择设备
    cmdList.push(ElementDiscoveryCommands.selectDeviceCommand(callback))
    // 取消选择设备
    cmdList.push(ElementDiscoveryCommands.deselectDeviceCommand(callback))
    return cmdList
  }

  // 链路右键
  static generateCommandsForLink(callback = () => {}) {
    const cmdList = []
    // 选择链路
    cmdList.push(ElementDiscoveryCommands.selectLinkCommand(callback))
    // 取消选择链路
    cmdList.push(ElementDiscoveryCommands.deselectLinkCommand(callback))
    return cmdList
  }
}

export default ElementDiscoveryCommands