import Serializer from "../data/serializer";

function RemotesService() {
  let commands = [];

  async function getRemotes() {
    return [];
  }

  async function getCommands() {
    return [].concat(commands);
  }

  async function createCommand(commandObject) {
    let command = Serializer.deserializeCommand(commandObject);
    let id = Math.random().toString(36).substr(2, 9);
    command.setId(id);
    commands.push(command);
    return command;
  }

  async function deleteCommand(commandId) {
    let index = commands.findIndex((command) => command.getId() === commandId);
    if (index >= 0) {
      commands.splice(index, 1);
    }
  }

  return {
    getRemotes,
    getCommands,
    createCommand,
    deleteCommand,
  };
}

RemotesService = new RemotesService();

export default RemotesService;
