text: "use strict";
  var __assign = (this && this.__assign) || function () {
      __assign = Object.assign || function(t) {
          for (var s, i = 1, n = arguments.length; i < n; i++) {
              s = arguments[i];
              for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                  t[p] = s[p];
          }
          return t;
      };
      return __assign.apply(this, arguments);
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.MappingService = void 0;
  var mappers_1 = require("../mappers");
  var models_1 = require("../models");
  var MappingService = /** @class */ (function () {
      function MappingService(config, richTextHtmlParser) {
          this.config = config;
          this.richTextHtmlParser = richTextHtmlParser;
          this.typeMapper = new mappers_1.TypeMapper();
          this.itemMapper = new mappers_1.ItemMapper(config, richTextHtmlParser);
          this.taxonomyMapper = new mappers_1.TaxonomyMapper();
          this.genericElementMapper = new mappers_1.GenericElementMapper();
          this.isDeveloperMode = config.isDeveloperMode === true ? true : false;
      }
      /**
       * Gets response for getting a single type
       * @param response Response data
       */
      MappingService.prototype.listContentTypesResponse = function (response) {
          var types = this.typeMapper.mapMultipleTypes(response.data);
          var pagination = new models_1.Pagination({
              skip: response.data.pagination.skip,
              count: response.data.pagination.count,
              limit: response.data.pagination.limit,
              nextPage: response.data.pagination.next_page
          });
          return new models_1.TypeResponses.ListContentTypesResponse(types, pagination, response, this.isDeveloperMode);
      };
      /**
       * Gets resposne for getting multiple types
       * @param response Response data
       * @param options Options
       */
      MappingService.prototype.viewContentTypeResponse = function (response) {
          var type = this.typeMapper.mapSingleType(response.data);
          return new models_1.TypeResponses.ViewContentTypeResponse(type, response, this.isDeveloperMode);
      };
      MappingService.prototype.itemsFeedResponse = function (response, queryConfig) {
          var itemsResult = this.itemMapper.mapItems({
              linkedItems: Object.values(response.data.modular_content),
              mainItems: response.data.items,
              queryConfig: queryConfig
          });
          return new models_1.ItemResponses.ItemsFeedResponse(itemsResult.items, itemsResult.linkedItems, response, this.isDeveloperMode);
      };
      MappingService.prototype.itemsFeedAllResponse = function (responses, queryConfig) {
          // join data from all responses before resolving items
          var allMainItems = [];
          var allLinkedItems = {};
          for (var _i = 0, responses_1 = responses; _i < responses_1.length; _i++) {
              var response = responses_1[_i];
              allMainItems.push.apply(allMainItems, response.data.items);
              allLinkedItems = __assign(__assign({}, allLinkedItems), response.data.modular_content);
          }
          var itemsResult = this.itemMapper.mapItems({
              linkedItems: Object.values(allLinkedItems),
              mainItems: allMainItems,
              queryConfig: queryConfig
          });
          return new models_1.ItemResponses.ItemsFeedAllResponse(itemsResult.items, itemsResult.linkedItems, responses, this.isDeveloperMode);
      };
      /**
       * Gets response for getting single item
       * @param response Response data
       * @param queryConfig Query configuration
       */
      MappingService.prototype.viewContentItemResponse = function (response, queryConfig) {
          var itemResult = this.itemMapper.mapSingleItemFromResponse(response.data, queryConfig);
          return new models_1.ItemResponses.ViewContentItemResponse(itemResult.item, itemResult.linkedItems, response, this.isDeveloperMode);
      };
      /**
       * Gets response for getting multiple items
       * @param response Response data
       * @param queryConfig Query configuration
       */
      MappingService.prototype.listContentItemsResponse = function (response, queryConfig) {
          var itemsResult = this.itemMapper.mapMultipleItemsFromResponse(response.data, queryConfig);
          var pagination = new models_1.Pagination({
              skip: response.data.pagination.skip,
              count: response.data.pagination.count,
              limit: response.data.pagination.limit,
              nextPage: response.data.pagination.next_page,
              totalCount: response.data.pagination.total_count
          });
          return new models_1.ItemResponses.ListContentItemsResponse(itemsResult.items, pagination, itemsResult.linkedItems, response, this.isDeveloperMode);
      };
      /**
       * Gets response for getting single taxonomy item
       * @param response Response data
       */
      MappingService.prototype.viewTaxonomyGroupResponse = function (response) {
          var taxonomy = this.taxonomyMapper.mapTaxonomy(response.data.system, response.data.terms);
          return new models_1.TaxonomyResponses.ViewTaxonomyGroupResponse(taxonomy, response, this.isDeveloperMode);
      };
      /**
       * Gets response for getting multiples taxonomies
       * @param response Response data
       */
      MappingService.prototype.listTaxonomyGroupsResponse = function (response) {
          var taxonomies = this.taxonomyMapper.mapTaxonomies(response.data.taxonomies);
          var pagination = new models_1.Pagination({
              skip: response.data.pagination.skip,
              count: response.data.pagination.count,
              limit: response.data.pagination.limit,
              nextPage: response.data.pagination.next_page
          });
          return new models_1.TaxonomyResponses.ListTaxonomyGroupsResponse(taxonomies, pagination, response, this.isDeveloperMode);
      };
      /**
       * Gets response for getting single content type element
       * @param response Response data
       */
      MappingService.prototype.viewContentTypeElementResponse = function (response) {
          var element = this.genericElementMapper.mapElement(response.data);
          return new models_1.ElementResponses.ViewContentTypeElementResponse(element, response, this.isDeveloperMode);
      };
      return MappingService;
  }());
  exports.MappingService = MappingService;
  //# sourceMappingURL=mapping.service.js.map