import { __awaiter } from "tslib";
export default class BaseListGetterApiConsumer {
    constructor({ defaultListObject = {}, listResponseHandler, } = {}) {
        this.responseHandler = (response) => {
            let items = [];
            const next = response.next || false;
            if (response.items) {
                items = response.items.map((item) => (Object.assign(Object.assign({}, this.defaultListObject), item)));
            }
            return Object.assign(Object.assign({}, response), { items, next });
        };
        this.defaultListObject = defaultListObject;
        if (listResponseHandler)
            this.userResponseHandler = listResponseHandler;
    }
    getLookup(params = {}) {
        return __awaiter(this, void 0, void 0, function* () {
            const defaultLookupParams = {
                size: 20,
                fields: ['id', 'name'],
            };
            try {
                const response = yield this.getList(Object.assign(Object.assign({}, defaultLookupParams), params));
                return response;
            }
            catch (err) {
                throw err;
            }
        });
    }
    setGetListMethod(method) {
        this.getList = method(this._getList.bind(this));
        return this;
    }
}
//# sourceMappingURL=base-list-getter-api-consumer.js.map