import express from 'express';
const bodyParser = require('body-parser');
{{#dependencies}}
import { {{this.className}} } from '{{this.relativePath}}';
{{/dependencies}}
import { createServer, proxy } from 'aws-serverless-express';



const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Dependency Injection
{{#dependencies}}
const {{this.instanceName}} = new {{this.className}}({{this.injectableClassNames}});
{{/dependencies}}

// Routes
{{#methods}}
app.{{httpMethod}}('{{#basePaths}}/{{this}}{{/basePaths}}{{path}}', (req, res) => {
  {{#if isParameterized}}
  const response = controller.{{name}}(req);
  {{else}}
  const response = controller.{{name}}();
  {{/if}}
  res.send(response);
});
{{/methods}}

// Lambda handler
const server = createServer(app);
export async function handler(event: any, context: any) {
  context.callbackWaitsForEmptyEventLoop = false;
  // Proxy the request to the Express server
  const response = await proxy(server, event, context, 'PROMISE').promise;

  console.log(response);

  return response;
};