import { __awaiter, __generator } from "tslib";
import { AddressLookupServiceProvider } from './address-lookup';
import { LoqateFindResponseBuilder, LoqateRetrieveResponseBuilder } from './address-lookup-loqate';
import { AddressLookupToAddressSummary, AddressRetrieveToAddress } from './address-lookup-response-mapper';
var AddressLookupLoqateService = /** @class */ (function () {
    function AddressLookupLoqateService(axios, key) {
        this.serviceProvider = AddressLookupServiceProvider.Loqate;
        this.axios = axios;
        this.key = key;
    }
    AddressLookupLoqateService.prototype.find = function (query) {
        return __awaiter(this, void 0, void 0, function () {
            var params, results;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        params = {
                            Key: this.key,
                            Text: query.input,
                            Container: (query.id) ? query.id : undefined,
                            Origin: (query.origin) ? query.origin : undefined,
                            Language: (query.language) ? query.language : undefined
                        };
                        return [4 /*yield*/, this.axios.get("https://api.addressy.com/Capture/Interactive/Find/v1.1/json3.ws", { params: params })];
                    case 1:
                        results = _a.sent();
                        return [2 /*return*/, results.data.Items.map(function (row) {
                                return (new LoqateFindResponseBuilder()
                                    .setRequest(params)
                                    .setResult(row)
                                    .build()).mapTo(new AddressLookupToAddressSummary());
                            })];
                }
            });
        });
    };
    AddressLookupLoqateService.prototype.retrieve = function (query) {
        return __awaiter(this, void 0, void 0, function () {
            var params, results;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        params = {
                            Id: query.id,
                            Key: this.key
                        };
                        return [4 /*yield*/, this.axios.get("https://api.addressy.com/Capture/Interactive/Retrieve/v1/json3.ws", { params: params })];
                    case 1:
                        results = _a.sent();
                        return [2 /*return*/, results.data.Items.map(function (row) {
                                return (new LoqateRetrieveResponseBuilder()
                                    .setRequest(params)
                                    .setResult(row)
                                    .build()).mapTo(new AddressRetrieveToAddress());
                            })];
                }
            });
        });
    };
    return AddressLookupLoqateService;
}());
export default AddressLookupLoqateService;
//# sourceMappingURL=address-lookup-loqate-service.js.map