import qs from 'query-string';
import BaseGetterApiConsumer from '../base-getter-api-consumer/base-getter-api-consumer';
export default class EndpointGetterApiConsumer extends BaseGetterApiConsumer {
    constructor({ baseUrl, instance }, params = {}) {
        super(params);
        this.instance = instance;
        this.baseUrl = baseUrl;
        if (params.nestedUrl)
            this.nestedUrl = params.nestedUrl;
    }
    getItem(params) {
        return this._getItem(params);
    }
    getNestedItem({ parentId, itemId, query, }) {
        const baseUrl = `${this.baseUrl}/${parentId}/${this.nestedUrl}`;
        return this._getItem({ itemId, query }, baseUrl);
    }
    async _getItem({ itemId, query }, baseUrl = this.baseUrl) {
        let url = `${baseUrl}/${itemId}`;
        if (query) {
            url += `?${qs.stringify(query, {
                skipEmptyString: true,
                skipNull: true,
            })}`;
        }
        try {
            let response = await this.instance.get(url);
            response = this.responseHandler(response);
            if (this.userResponseHandler) {
                response = this.userResponseHandler(response);
            }
            return response;
        }
        catch (err) {
            throw err;
        }
    }
}
//# sourceMappingURL=endpoint-getter-api-consumer.js.map