var path = require('path');
var util = require('util');
var support = require('../support');
var _ = support.Utilities;
var reflectAccessors = support.ReflectAccessors;
var delegates = require('delegates');
var AbstractController = require('./abstract');


var RequestController = AbstractController.extend({

  /**
   * @param {Context} ctx Koa.Context instance from the request
   */
  constructor: function(ctx) {

    AbstractController.apply(this, arguments);

    this.ctx = ctx;

    reflectAccessors(this, this.app, 'log');

    _.merge(
      this.locals,
      this.params,
      this.router.match,
      this.request.body,
      this.request.query
    );

    reflectAccessors(this.locals, this.ctx, ['session', 'cookies', 'params']);

  }

});

_.extend(RequestController.prototype,
  require('./responders'),
  require('./rendering')
);


// add default renderers which are all handled by koa and require
// no special operations before being served to koa
[
  'json',
  'stream',
  'buffer',
  'text',
  'html',
  'default'
].forEach(function(type) {

  RequestController.addRenderer(type, function* (data) {
    return yield data;
  });

});


// setup proxies on prototype to ctx object prop
delegates(RequestController.prototype, 'ctx')
  .method('accepts')
  .method('redirect')
  .method('throw')
  .access('app')
  .access('body')
  .access('session')
  .access('cookies')
  .getter('router')
  .getter('request')
  .getter('response')


module.exports = RequestController;
@@ -507,20 +507,19 @@
 s(this, 
-this
+ctx
 .app, 'l
@@ -533,53 +533,52 @@
     
-_.merge(%0A      this.locals,%0A      this.params
+this.params = ctx.params = _.merge(%0A      %7B%7D
 ,%0A  
@@ -654,24 +654,153 @@
 ery%0A    );%0A%0A
+    // ctx locals should already be defined.%0A    // @TODO replace with ctx.state when appropriate%0A    this.locals = ctx.locals;%0A%0A
     reflectA
@@ -821,21 +821,16 @@
 locals, 
-this.
 ctx, %5B's
@@ -861,17 +861,16 @@
 ams'%5D);%0A
-%0A
   %7D%0A%0A%7D);

repair params / locals referencing issue in ctrl