<?php
declare(strict_types=1);

class Response
{
    public static function json(
        string $status,
        string $message,
        array $data = [],
        int $httpCode = 200
    ): void {
        if (!headers_sent()) {
            http_response_code($httpCode);
            header('Content-Type: application/json; charset=utf-8');
        }

        echo json_encode([
            'status'  => $status,
            'message' => $message,
            'data'    => $data
        ], JSON_UNESCAPED_UNICODE);

        exit;
    }

    public static function success(string $message, array $data = []): void
    {
        self::json('success', $message, $data, 200);
    }

    public static function error(string $message, int $httpCode = 400): void
    {
        self::json('error', $message, [], $httpCode);
    }
}
