<?php
namespace App\Core;

class Response {
    protected $baseUrl = '';

    public function __construct() {
        $this->baseUrl = (defined('BASE_URL') ? BASE_URL : '');
    }

    public function setStatusCode(int $code) {
        http_response_code($code);
    }

    public function redirect($url) {
        header("Location: $url");
        exit;
    }

    public function render($view, $data = []) {
        $baseUrl = $this->baseUrl;
        extract($data);
        
        $viewFile = __DIR__ . '/../Views/' . $view . '.php';
        if (file_exists($viewFile)) {
            include $viewFile;
        } else {
            echo "Görünüm dosyası bulunamadı: $view";
        }
    }

    public function json($data) {
        header('Content-Type: application/json; charset=utf-8');
        echo json_encode($data, JSON_UNESCAPED_UNICODE);
        exit;
    }
}
