<?php

use App\Middleware\AfterRouteMiddleware;
use App\Middleware\BeforeRouteMiddleware;
use Snaju\Inception\Http\Request\Controller;
use Snaju\Inception\Http\Request\WebRequest;

// You can specify middleware to run on every request by creating a controller
// instance and passing an array of middleware.
// uncomment the middleware in the get method to see an example of it working.
// check the browser console and you should see a 404 request with new data added
// that was done via the AfterRouteMiddleware.
// The controller($middleware = []) helper function can also be used
//$controller = new Controller([]);

controller()->get(function(WebRequest $request, $id) {
    // To render a template, use the template id
//    render('home');

    // To send json, return the response and specify json data
    return response()->json([
        'data' => [
            'id' => $id,
            'hello' => 'world',
            '123' => '456',
            'nestedArrayTest' => [
                'users' => [
                    [
                        'name' => 'Bob Da Builder',
                        'email' => 'builditbob@gmail.com',
                    ],
                    [
                        'name' => 'Rick Roll',
                        'email' => 'rr@rtube.com',
                    ],
                ]
            ],
        ]
    ], 201);


}, [
//    BeforeRouteMiddleware::class,
//    AfterRouteMiddleware::class,
]);


controller()->post(function(WebRequest $request) {
    echo 'post request received';
});


controller()->delete(function(WebRequest $request, $id) {
    echo 'delete request received';
});


controller()->fallback(function() {
    echo 'fallback function called because method did not match';
});