<?php

require 'vendor/autoload.php';

use Origo\Services\Template;
use Origo\Entity\User;
use Origo\Services\Router;
use Origo\Services\Renderer;
use Origo\Services\Request;

// Need to handle api routes differently.
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

/* 1|bender|dan@danchadwickdesign.com|2025-12-19 00:51:10|aa7101dc6e2fe541ac5a44352c24d15052723b70ceecd5fc6d7fe71d0721c9aa|0 */
$router = new Router();
$renderer = new Renderer();

// If the route doesn't, render the 403 page.
if (!$router->routeExists($path)) {
  echo $renderer->render403();
  die();
}

// If the user does not have a session cookie, 403.
// now we dont have to do this in every controller.
// Still allow login on homepage.
$request = new Request();
$allowed_paths = [
  '/',
  '/user-login',
  '/api/v1/webhook'
];

if (
  !$request->getCookie('ORIGOSESS') && 
  !in_array($path, $allowed_paths)
) {
  echo $renderer->render403();
  die();
}

$controller = $router->getRouteController($path);
$controller_cl = new $controller();
$response = $controller_cl->getResponse();

echo $response;

?>
