/**
 * Get filenames for each lang from context.
 * @function serverside.response._getLocaledFilenamesFromContext
 * @param {object} context - Server context object.
 * @protected
 * @ignore
 * @author Taka Okunishi
 */

var util = require('util'),
    format = util.format;

module.exports = function (context, contextKeyFormat) {
    context.assertKeys(['SUPPORTED_LANGS']);

    var langs = context.SUPPORTED_LANGS;
    if (typeof(langs) === 'string') {
        langs = langs.split(',');
    }
    var result = {};
    langs.forEach(function (lang) {
        var key = format(contextKeyFormat, lang.toUpperCase()),
            filename = context[key];

        if (!filename) {
            var errMsg = format('"context.%s" not found', key, lang);
            throw new Error(errMsg);
        }
        result[lang] = filename;
    });
    return result;
};