<?php

declare(strict_types=1);

namespace App\Core;

class Response
{
    public function setStatusCode(int $code): void
    {
        http_response_code($code);
    }

    public function redirect(string $path): void
    {
        if (str_starts_with($path, '/') && !str_starts_with($path, '//')) {
            $path = app()->publicBasePath() . $path;
        }

        header("Location: {$path}");
        exit;
    }

    public function back(): void
    {
        $target = $_SERVER['HTTP_REFERER'] ?? '/';
        $this->redirect($target);
    }
}
