define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Magento2AbstractApiService = /** @class */ (function () {
        function Magento2AbstractApiService($http, $q, API_URL, API_ENDPOINT) {
            this.$http = $http;
            this.$q = $q;
            this.API_URL = API_URL;
            this.API_ENDPOINT = API_ENDPOINT;
        }
        Magento2AbstractApiService.prototype.get = function (field, values, orderBy, orderDirection, conditionType, pageSize, currentPage) {
            var _this = this;
            if (conditionType === void 0) { conditionType = 'in'; }
            if (pageSize === void 0) { pageSize = '120'; }
            if (currentPage === void 0) { currentPage = '1'; }
            var deferred = this.$q.defer();
            this.$http
                .get(this.API_URL + "/" + this.API_ENDPOINT, {
                params: this.getSearchParams(field, values, orderBy, orderDirection, conditionType, pageSize, currentPage)
            })
                .then(function (res) {
                deferred.resolve(_this.prepareResponse(res));
            });
            return deferred.promise;
        };
        Magento2AbstractApiService.prototype.prepareResponse = function (res) {
            return res;
        };
        Magento2AbstractApiService.prototype.getSearchParams = function (field, value, orderBy, orderDirection, conditionType, pageSize, currentPage) {
            if (conditionType === void 0) { conditionType = 'in'; }
            if (pageSize === void 0) { pageSize = '120'; }
            if (currentPage === void 0) { currentPage = '1'; }
            var params = {
                'searchCriteria[filterGroups][0][filters][0][field]': field,
                'searchCriteria[filterGroups][0][filters][0][value]': value,
                'searchCriteria[filterGroups][0][filters][0][conditionType]': conditionType,
                'searchCriteria[sortOrders][0][field]': orderBy,
                'searchCriteria[sortOrders][0][direction]': orderDirection,
                'searchCriteria[pageSize]': pageSize,
                'searchCriteria[currentPage]': currentPage
            };
            return params;
        };
        Magento2AbstractApiService.prototype.getAttributeValues = function (products, attributeName) {
            var values = [];
            for (var _i = 0, products_1 = products; _i < products_1.length; _i++) {
                var product = products_1[_i];
                var tabAttribute = product.custom_attributes.find(function (attribute) {
                    return attribute.attribute_code === attributeName;
                });
                if (!tabAttribute) {
                    continue;
                }
                ;
                var productValue = tabAttribute.value;
                if (productValue instanceof Array) {
                    for (var _a = 0, productValue_1 = productValue; _a < productValue_1.length; _a++) {
                        var singleProductValue = productValue_1[_a];
                        this.addToArray(values, singleProductValue);
                    }
                }
                else {
                    this.addToArray(values, productValue);
                }
            }
            return values;
        };
        Magento2AbstractApiService.prototype.addToArray = function (data, value) {
            if (data.indexOf(value) === -1 && value) {
                data.push(value);
            }
        };
        return Magento2AbstractApiService;
    }());
    exports.Magento2AbstractApiService = Magento2AbstractApiService;
});
//# sourceMappingURL=magento2.abstract.api.service.js.map