'use strict';

/**
 * @file
 * Basic service provider. Discovers and initializes the transforms.
 */

import Transform from './lib/Transforms';

/**
 * Initialization of the provider and the underlying services.
 *
 * @param {Object} config Object containing the necessary parameters.
 * @param {Object} logger logger object with methods for logging.
 *
 * @api public
 */
export default function Provider(logger) {

  /**
   * Object with all clients registered on the provider
   * @type {{}}
   */
  const clients = {};

  /**
   * Map of all transforms registered on the provider
   * @type {Map}
   */
  const transforms = new Map();

  /**
   * Method for registering a single transform
   * @param transform
   */
  function registerTransform(transformObject) {
    const name = transformObject.event();
    if (transforms.has(name)) {
      throw new Error(`Event '${name}' already registered`);
    }
    const transform = Transform(transformObject, clients, logger);
    transforms.set(name, transform);

    return transform;
  }

  /**
   * Method for registering a service client
   *
   * @param name
   * @param client
   */
  function registerServiceClient(name, client) {
    if (clients[name]) {
      throw new Error(`Client '${name}' already registered`);
    }
    clients[name] = client;

    return clients;
  }

  function trigger(event, params, context) {
    return transforms.get(event).trigger(params, context);
  }

  // we are going to reimplement a simpler mechanism to call the transformers
  function execute(name, params, context){
    return {};
  }
    
  function availableTransforms() {
    return transforms.keys();
  }

  return {
    registerTransform,
    registerServiceClient,
    availableTransforms,
    trigger
  };
}

@@ -1557,17 +1557,56 @@
 context)
-%7B
+ %7B // eslint-disable-line no-unused-vars
 %0A    ret
@@ -1617,20 +1617,16 @@
 %7B%7D;%0A  %7D%0A
-    
 %0A  funct
@@ -1774,16 +1774,29 @@
 sforms,%0A
+    execute,%0A
     trig

fix linting errors in Provider.js, after execute was added