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

var object = require('../../lib/object'),
    deepCopy = object.deepCopy,
    _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
        },
        responseEnhanceFunctions: {
            pageNotFound: rs.defineResPageNotFound,
            redirect: rs.defineResRedirect,
            somethingWrong: rs.defineResSomethingWrong
        },
        middlewares: [
            md.defineAccessLogMiddleware,
            md.defineReqEnhanceMiddleware,
            md.defineResEnhanceMiddleware,
            md.defineClusterDomainMiddleware,
            md.definePublicFilesMiddleware,
            md.definePageNotFoundMiddleware,
            md.defineSomethingWrongMiddleware
        ]
    });


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

