var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../magento2.abstract.api.service"], function (require, exports, magento2_abstract_api_service_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**
     * Service to communicate with the magento2 API
     */
    var WidgetCategoryProductsService = /** @class */ (function (_super) {
        __extends(WidgetCategoryProductsService, _super);
        function WidgetCategoryProductsService($http, $q, API_URL, API_PRODUCTS_ENDPOINT) {
            var _this = _super.call(this, $http, $q, API_URL, API_PRODUCTS_ENDPOINT) || this;
            _this.$http = $http;
            _this.$q = $q;
            _this.API_URL = API_URL;
            _this.API_PRODUCTS_ENDPOINT = API_PRODUCTS_ENDPOINT;
            /**
             * URL to the API endpoint
             */
            _this.url = location.hostname;
            return _this;
        }
        /**
         * Set the attribute to generate the groups from
         *
         * @param attribute The attribute_code to generate groups from
         */
        WidgetCategoryProductsService.prototype.setAttribute = function (attribute) {
            this.attribute = attribute;
        };
        /**
         * Set the URL to the API endpoint
         *
         * @param attribute The URL to the API endpoint
         */
        WidgetCategoryProductsService.prototype.setUrl = function (url) {
            this.url = url;
        };
        /**
         * Get an observable which returns the requested products
         *
         * @param categories Comma-separated list of category-ids to get products from
         */
        WidgetCategoryProductsService.prototype.get = function (categories) {
            return _super.prototype.get.call(this, 'category_id', categories, 'created_at', 'DESC');
        };
        /**
         * Compute the returned response before passing it to the controller
         *
         * @param res The raw HTTP-Response coming from angularjs
         */
        WidgetCategoryProductsService.prototype.prepareResponse = function (res) {
            return {
                attributeValues: this.getAttributeValues(res.data.items, this.attribute),
                products: res.data.items
            };
        };
        return WidgetCategoryProductsService;
    }(magento2_abstract_api_service_1.Magento2AbstractApiService));
    exports.WidgetCategoryProductsService = WidgetCategoryProductsService;
});
//# sourceMappingURL=widget.category.products.service.js.map