var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { TaJson } from "ta-json";
import Guard from "../guard";
import { AllFacetValuesResponse } from "../models/search/all-facet-values-response";
import { SearchResponse } from "../models/search/search-response";
import { ResponseHandler } from "./response-handler";
export class SearchClient {
    constructor(client) {
        Guard.notNullOrUndefined(client);
        this._client = client;
    }
    searchAsync(searchRequest, cancelCallback) {
        return __awaiter(this, void 0, void 0, function* () {
            Guard.notNullOrUndefined(searchRequest);
            const searchLink = yield this._client.linkHelper.searchLinkAsync();
            const response = yield this._client.raw.postAsync(searchLink.href, TaJson.serialize(searchRequest), undefined, cancelCallback);
            ResponseHandler.handleErrors(response);
            const searchResponse = TaJson.deserialize(response.content, SearchResponse);
            return searchResponse;
        });
    }
    allFacetsAsync(allFacetsRequest, cancelCallback) {
        return __awaiter(this, void 0, void 0, function* () {
            Guard.notNullOrUndefined(allFacetsRequest);
            const allFacetsLink = yield this._client.linkHelper.allFacetsAsync();
            const response = yield this._client.raw.postAsync(allFacetsLink.href, TaJson.serialize(allFacetsRequest), undefined, cancelCallback);
            ResponseHandler.handleErrors(response);
            const allFacetsResponse = TaJson.deserialize(response.content, AllFacetValuesResponse);
            return allFacetsResponse;
        });
    }
}
//# sourceMappingURL=search-client.js.map