<?php
function checkAccessToEndpoint($url,$method='get', $data = null) {
    $ch = curl_init();

    // Set the URL and Method
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));

    // Set Timeout (Connect + Execution)
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

    // Ensure we get the response as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Set Headers for JSON
    $headers = [
        'Content-Type: application/json',
        'Accept: application/json'
    ];
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    // Attach data if it's a POST/PUT request
    if ($data) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    }

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    // Check for cURL errors (like timeouts)
    if (curl_errno($ch)) {
        $error_msg = curl_error($ch);
        curl_close($ch);
        return false;
    }

    curl_close($ch);

    // Return decoded JSON
    $data= json_decode($response, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        return false;
    }
    return $response;
}

include_once __DIR__.'/info.php';

include_once __DIR__.'/home-screen.php';

include_once __DIR__.'/promotion.php';

include_once __DIR__.'/kits-library.php';

include_once __DIR__.'/enqueue.php';