<?php

declare(strict_types=1);

namespace App\Core;

final class Response
{
    public static function redirect(string $target): never
    {
        if (str_starts_with($target, 'http://') || str_starts_with($target, 'https://')) {
            header('Location: ' . $target);
            exit;
        }

        $parts = explode('&', $target, 2);
        $page = urlencode($parts[0]);
        $query = isset($parts[1]) ? '&' . $parts[1] : '';

        header('Location: index.php?page=' . $page . $query);
        exit;
    }

    public static function status(int $code): void
    {
        http_response_code($code);
    }
}
