<?php
declare(strict_types=1);

class Controller {
    
    /**
     * Load the requested model and return an instance of it.
     */
    public function model(string $model) {
        $modelPath = '../app/Models/' . $model . '.php';
        
        if (file_exists($modelPath)) {
            require_once $modelPath;
            return new $model();
        }
        
        // 🛡️ Log the missing model to prevent silent failures for developers
        error_log("Critical: Model file not found - " . $model);
        die("System error: Unable to load required resources.");
    }

    /**
     * Load the requested view and pass data to it.
     */
    public function view(string $view, array $data = []): void {
        $viewPath = '../app/Views/' . $view . '.php';
        
        if (file_exists($viewPath)) {
            require_once $viewPath;
        } else {
            // 🛡️ Graceful degradation if a view goes missing
            error_log("Critical: View file not found - " . $view);
            die("We are updating this page. Please check back in a few minutes.");
        }
    }
}