"use strict";

import endpoint from "./endpoint";
import * as requests from "./requests";

/**
 * Abstract representation of a exhibition.
 */
export default class Exhibition {

  /**
   * Constructor.
   *
   * @param  {Tenant} tenant     The tenant instance.
   * @param  {String} exhibitionId  The exhibition id.
   */
  constructor(tenant, exhibitionId) {

    /**
     * The tenant.
     * @type {Tenant}
     */
    this.tenant = tenant;

    /**
     * The value id.
     * @type {String}
     */
    this.exhibitionId = exhibitionId;
  }

  /**
   * Retrieves exhibition.
   *
   * @param  {Object} options         The options object.
   * @return {Promise<Object, Error>}
   */
  get(options = {}) {
    return this.tenant.execute(
      {
        path: endpoint("exhibition", this.exhibitionId)
      },
      options
    );
  }

  /**
   * Updates the value with the specified properties.
   *
   * @param {String} visibility     The exhibition visibility
   * @param  {Object} options       The options object.
   * @return {Promise<Object, Error>}
   */
  changeExhibitionVisibility(visibility, options = {}) {
    return this.tenant.execute(
      requests.changeExhibitionVisibility(this.exhibitionId, visibility),
      options
    );
  }

  /**
   * Updates the description of the exhibition.
   *
   * @param {String} name           The exhibition name.
   * @param {String} description    The exhibition description.
   * @param {String} pictureUri     The exhibition picture.
   * @param  {Object} options       The options object.
   * @return {Promise<Object, Error>}
   */
  update(name, description, pictureUri, options = {}) {
    return this.tenant.execute(
      requests.updateExhibition(this.exhibitionId, name, description, pictureUri),
      options
    );
  }

  /**
   * Delete current exhibition
   *
   * @param  {Object} options             The options object.
   * @returns {Promise.<Object, Error>}
   */
  remove(options = {}) {
    return this.tenant.execute(
      requests.deleteExhibition(this.exhibitionId),
      options
    );
  }

  /**
   * Retrieves exhibition clusters.
   *
   * @param  {Object} options         The options object.
   * @return {Promise<Object, Error>}
   */
  getPublishedClusters(options = {}) {
    return this.tenant.execute(
      {
        path: endpoint("exhibitionClusters", this.exhibitionId)
      },
      options
    ).then((response) =>
      {
        if (response["_embedded"]) {
          response["_embedded"]["be:exhibition_clusters"].forEach((cluster) => {
            cluster.users = response["_embedded"]["be:user"];
          });
          return response["_embedded"]["be:exhibition_clusters"];
        } else {
          return [];
        }
      });
  }

  /**
   * Retrieves exhibition cluster.
   * @param  {String} clusterHeadId      The id of the cluster head.
   * @param  {Object} options         The options object.
   * @return {Promise<Object, Error>}
   */
  getPublishedCluster(clusterHeadId, options = {}) {
    return this.tenant.execute(
      {
        path: endpoint("exhibitionCluster", this.exhibitionId, clusterHeadId)
      },
      options
    ).then((response) => {
      response.users = response["_embedded"]["be:user"];
      return response;
    });
  }

  /**
   * Retrieves exhibition instances.
   *
   * @param  {Object} options         The options object.
   * @return {Promise<Object, Error>}
   */
  getPublishedInstances(options = {}) {
    return this.tenant.execute(
      {
        path: endpoint("exhibitionInstances", this.exhibitionId)
      },
      options
    ).then((response) => {
      if (response["_embedded"]) {
        response["_embedded"]["be:instance"].forEach((instance) => {
          instance.users = response["_embedded"]["be:user"];
        });
        return response["_embedded"]["be:instance"];
      } else {
        return [];
      }
    });
  }

  /**
   * Retrieves exhibition instances.
   * @param  {String} instanceId      The id of the instance.
   * @param  {Object} options         The options object.
   * @return {Promise<Object, Error>}
   */
  getPublishedInstance(instanceId, options = {}) {
    return this.tenant.execute(
      {
        path: endpoint("exhibitionInstance", this.exhibitionId, instanceId)
      },
      options
    ).then((response) => {
      response.users = response["_embedded"]["be:user"];
      return response;
    });
  }
}




@@ -2410,27 +2410,19 @@
 onse) =%3E
-%0A     
  %7B%0A
-  
       if
@@ -2444,26 +2444,24 @@
 bedded%22%5D) %7B%0A
-  
         resp
@@ -2523,26 +2523,24 @@
 uster) =%3E %7B%0A
-  
           cl
@@ -2591,32 +2591,28 @@
 %22%5D;%0A        
-  
 %7D);%0A
-  
         retu
@@ -2665,26 +2665,24 @@
 rs%22%5D;%0A      
-  
 %7D else %7B%0A   
@@ -2674,26 +2674,24 @@
    %7D else %7B%0A
-  
         retu
@@ -2703,22 +2703,18 @@
 ;%0A      
-  %7D%0A  
+%7D%0A
     %7D);%0A

Correct indentation