<?php
// ============================================================
// backend/helpers/response.php
// ============================================================

function sendSuccess($data = [], string $message = 'Success', int $code = 200): void {
    http_response_code($code);
    header('Content-Type: application/json');
    echo json_encode([
        'success' => true,
        'message' => $message,
        'data'    => $data,
    ]);
    exit;
}

function sendError(string $message = 'Error', int $code = 400, $errors = null): void {
    http_response_code($code);
    header('Content-Type: application/json');
    $payload = ['success' => false, 'message' => $message];
    if ($errors !== null) $payload['errors'] = $errors;
    echo json_encode($payload);
    exit;
}
