/**
 * Computes the final instance state after hook is executed.
 *
 * @param {Object} ctx The hook context
 * @return {Object} The final instance state
 */
exports.getFinalState = function(ctx) {
    if (ctx.isNewInstance)
        return ctx.instance;
    if (ctx.currentInstance) {
        return Object.assign({},
            ctx.currentInstance.__data,
            ctx.data || ctx.instance
        );
    }

    return null;
};

/**
 * Determines if hook is affecting multiple instances.
 *
 * @param {Object} ctx The hook context
 * @return {Boolean} %true for multiple instances, %false otherwhise
 */
exports.isMultiple = function(ctx) {
    return !ctx.isNewInstance && !ctx.currentInstance;
};

/* exports.fkToValue = async function(instance, ctx, model) {
    let transaction = ctx.options && ctx.options.transaction;
    let cleanInstance = JSON.parse(JSON.stringify(instance));
    let result = {};
    for (let key in cleanInstance) {
        let val = cleanInstance[key];
        if (val === undefined || val === null) continue;
        for (let key1 in model.relations) {
            let val1 = model.relations[key1];
            if (val1.keyFrom == key && key != 'id') {
                let recordSet = await val1.modelTo.findById(val, {}, {transaction});
                val = recordSet.name || recordSet.id; // FIXME preparar todos los modelos con campo name
                break;
            }
        }
        result[key] = val;
    }
    return result;
};
 */