<?php

namespace brain\controllers;

use brain\controllers\APIController;

class RouteController
{
    protected $api;
    public function __construct()
    {
        $this->api = new APIController();
    }

    public function start($request)
    {
        $request = ltrim($request, " / ");
        $params = explode("/", $request);
        if ($params[0] == "") {
            require "brain/views/front.php";
        } else {
            switch ($params[0]) {
                case "api":
                    //get api controller to handle route
                    $result = $this->api->handleRoute($params);
                    header("Content-Type: application/json; charset=utf-8");
                    echo $result;
                    break;
                default:
                    http_response_code(404);
                    require "brain/views/404.php";
                    break;
            }
        }
    }
}
