<?php

declare(strict_types=1);

namespace App\Framework\Http;

use App\Framework\Http\Cookies\Cookies;

final readonly class HttpRequest implements Request
{
    #public array $parsedBody;

    public function __construct(
        public Method            $method = Method::GET,
        public Headers           $headers = new Headers(),
        public string            $body = '',
        public string            $path = '',
        public array             $queryParams = [],
        public UploadedFiles     $files = new UploadedFiles([]),
        public Cookies           $cookies = new Cookies(),
        public ServerEnvironment $server = new ServerEnvironment(),
        public RequestId         $id = new RequestId(),
        public RequestBody       $parsedBody = new RequestBody(Method::GET, new Headers(), '', [])
    ) {
        #$this->parsedBody = new RequestBodyParser()->parse($this);
    }

    // Hilfsmethode zum Abrufen von Query-Parametern
    public function getQuery(string $key, mixed $default = null): mixed
    {
        return $this->queryParams[$key] ?? $default;
    }
}
