<?php
// Standard API Response Helper

function jsonResponse($data = [], $status = 200)
{
    http_response_code($status);
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode(['success' => true, 'data' => $data]);
    exit();
}

function jsonError($message, $status = 400, $code = null)
{
    http_response_code($status);
    header('Content-Type: application/json; charset=utf-8');
    $response = ['success' => false, 'error' => $message];
    if ($code)
        $response['code'] = $code;
    echo json_encode($response);
    exit();
}
?>