/**
 * Create a production server context.
 * @function serverside.context.newProductionContext
 * @param {object} [context] - Predefined context object.
 * @returns {object} - Defined server context object.
 * @author Taka Okunishi
 *
 */

var object = require('../../lib/object'),
    deepCopy = object.deepCopy,
    fallbackCopy = object.fallbackCopy,
    _newContext = require('./_new_context'),
    rq = require('../request'),
    rs = require('../response'),
    md = require('../middleware');

exports = module.exports = function (context) {
    context = _newContext(context, {
        requestEnhanceFunctions: {
            lang: rq.defineReqLang,
            apemanId: rq.defineReqApemanId
        },
        responseEnhanceFunctions: {
            pageNotFound: rs.defineResPageNotFound,
            redirect: rs.defineResRedirect,
            somethingWrong: rs.defineResSomethingWrong
        },
        middlewares: [
            md.defineAccessLogMiddleware,
            md.defineReqEnhanceMiddleware,
            md.defineResEnhanceMiddleware,
            md.defineApemanIdMiddleware,
            md.defineClusterDomainMiddleware,
            md.definePublicFilesMiddleware,
            md.definePageNotFoundMiddleware,
            md.defineErrorLogMiddleware,
            md.defineSomethingWrongMiddleware
        ]
    });

    var constants = require('../constants/production-constants');
    return deepCopy(constants, context);
};
