<?php
function jsonResponse($success, $message, $data = [], $pagination = null, $statusCode = 200) {
    http_response_code($statusCode);
    header('Content-Type: application/json');
    $response = [
        'success' => $success,
        'message' => $message,
    ];
    if (!$success) {
        $response['errors'] = $data;
    } else {
        $response['data'] = $data;
    }
    if ($pagination) {
        $response['pagination'] = $pagination;
    }
    echo json_encode($response);
    exit;
}

function sendResponse($data = [], $message = '', $statusCode = 200) {
    jsonResponse(true, $message, $data, null, $statusCode);
}

function sendError($message = '', $errors = [], $statusCode = 400) {
    jsonResponse(false, $message, $errors, null, $statusCode);
}
