<?php
require_once __DIR__ . '/../models/Game.php';
require_once __DIR__ . '/../models/Category.php';

class GameController {
    private $gameModel;
    private $categoryModel;

    public function __construct() {
        $this->gameModel = new Game();
        $this->categoryModel = new Category();
    }

    public function show($slug) {
        $game = $this->gameModel->getGameBySlug($slug);
        
        if (!$game) {
            header('HTTP/1.0 404 Not Found');
            include __DIR__ . '/../views/404.php';
            return;
        }
        
        $relatedGames = $this->gameModel->getRelatedGames($game['category_id'], $game['id'], 12);
        $popularCategories = $this->categoryModel->getPopularCategories(10);
        
        // Set title variables for SEO
        $gameTitle = $game['title'];
        $pageTitle = 'Play ' . $game['title'];
        $pageDescription = $game['description'] ?? 'Play ' . $game['title'] . ' game online for free.';
        
        include __DIR__ . '/../views/game.php';
    }
}
