"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const resolve_attribute_value_name_conflicts_function_1 = require("./functions/resolve-attribute-value-name-conflicts.function");
function addUpdateExpression(updateExpression, params) {
    addExpression('UpdateExpression', updateExpression, params);
}
exports.addUpdateExpression = addUpdateExpression;
function addExpression(expressionType, condition, params) {
    const nameSafeCondition = resolve_attribute_value_name_conflicts_function_1.resolveAttributeValueNameConflicts(condition, params);
    const expressionAttributeNames = Object.assign({}, params.ExpressionAttributeNames, nameSafeCondition.attributeNames);
    const expressionAttributeValues = Object.assign({}, params.ExpressionAttributeValues, nameSafeCondition.attributeValues);
    if (!lodash_1.isEmpty(expressionAttributeNames)) {
        params.ExpressionAttributeNames = expressionAttributeNames;
    }
    if (!lodash_1.isEmpty(expressionAttributeValues)) {
        params.ExpressionAttributeValues = expressionAttributeValues;
    }
    const expression = Reflect.get(params, expressionType);
    if (lodash_1.isString(expression)) {
        switch (expressionType) {
            case 'UpdateExpression':
                if (expression !== '') {
                    throw new Error('params.UpdateExpression is not empty, please use the UpdateRequest.operations() method to define all the update operations');
                }
                break;
            default:
                ;
                params[expressionType] = `${expression} AND ${nameSafeCondition.statement}`;
        }
    }
    else {
        ;
        params[expressionType] = nameSafeCondition.statement;
    }
}
exports.addExpression = addExpression;
//# sourceMappingURL=param-util.js.map