<?php
namespace Core;

class App {
    private Router $router;

    public function __construct() {
        Session::start();
        $this->setSecurityHeaders();
        $this->router = new Router();
        $this->loadRoutes();
    }

    public function run(): void {
        $req = new Request();
        $this->router->dispatch($req->method, $req->uri);
    }

    private function loadRoutes(): void {
        require ROOT . '/config/routes.php';
        registerRoutes($this->router);
    }

    private function setSecurityHeaders(): void {
        header('X-Frame-Options: SAMEORIGIN');
        header('X-Content-Type-Options: nosniff');
        header('X-XSS-Protection: 1; mode=block');
        header('Referrer-Policy: strict-origin-when-cross-origin');
        header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://www.gstatic.com; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:;");
    }
}
