<?php

function json_response(bool $success, string $message = '', array $data = [], int $http_code = 200): void
{
    if (!headers_sent()) {
        http_response_code($http_code);
        header('Content-Type: application/json; charset=utf-8');
    }

    echo json_encode([
        'success' => $success,
        'message' => $message,
        'data'    => $data
    ], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);

    exit;
}