import dcopy from 'deep-copy';
import sanitizer from '../../_shared/utils/sanitizer';
import BaseUpdaterApiConsumer from '../base-updater-api-consumer/base-updater-api-consumer';
export default class SdkUpdaterApiConsumer extends BaseUpdaterApiConsumer {
    constructor(SDKMethod, params = {}) {
        super(params);
        this.SDKMethod = SDKMethod;
    }
    updateItem({ itemId, itemInstance, }) {
        let itemCopy = dcopy(itemInstance);
        if (this.preRequestHandler) {
            itemCopy = this.preRequestHandler(itemCopy);
        }
        if (this.fieldsToSend) {
            itemCopy = sanitizer(itemCopy, this.fieldsToSend);
        }
        return this._updateItem([itemId, itemCopy]);
    }
    updateNestedItem({ parentId, itemId, itemInstance, }) {
        let itemCopy = dcopy(itemInstance);
        if (this.preRequestHandler) {
            itemCopy = this.preRequestHandler(itemCopy, parentId);
        }
        if (this.fieldsToSend) {
            itemCopy = sanitizer(itemCopy, this.fieldsToSend);
        }
        return this._updateItem([parentId, itemId, itemCopy]);
    }
    async _updateItem(args) {
        try {
            // @ts-ignore
            const response = await this.SDKMethod(...args);
            return this.responseHandler(response);
        }
        catch (err) {
            throw err;
        }
    }
}
//# sourceMappingURL=sdk-updater-api-consumer.js.map