<?php

namespace engine\http;

abstract class Response
{
    protected mixed $data;

    public function __construct(
        protected(set) HTTPCode $code
    ) {}

    public function send(): void {
        http_response_code($this->code->value);
        $headers = $this->getHeaders();
        if ($headers) {
            foreach ($headers as $header)
                header($header);
        }
        echo $this->getBody();
    }

    abstract public function getHeaders(): ?array;
    abstract public function getBody(): string;
}
