text: import cloneDeep from 'lodash/cloneDeep';
  import { freezeSys, toPlainObject } from 'contentful-sdk-core';
  import enhanceWithMethods from '../enhance-with-methods';
  import createOrganizationApi from '../create-organization-api';
  import { wrapCollection } from '../common-utils';
  
  /**
   * This method creates the API for the given organization with all the methods for
   * reading and creating other entities. It also passes down a clone of the
   * http client with an organization id, so the base path for requests now has the
   * organization id already set.
   * @private
   * @param http - HTTP client instance
   * @param data - API response for an Organization
   * @return {Organization}
   */
  export function wrapOrganization(http, data) {
    var org = toPlainObject(cloneDeep(data));
    var baseURL = (http.defaults.baseURL || '').replace('/spaces/', '/organizations/') + org.sys.id + '/'; // @ts-expect-error
  
    var orgScopedHttpClient = http.cloneWithNewParams({
      baseURL: baseURL
    });
    var orgApi = createOrganizationApi({
      http: orgScopedHttpClient
    });
    var enhancedOrganization = enhanceWithMethods(org, orgApi);
    return freezeSys(enhancedOrganization);
  }
  /**
   * This method normalizes each organization in a collection.
   * @private
   */
  
  export var wrapOrganizationCollection = wrapCollection(wrapOrganization);