<?php

function curlWorkspaceSmsMailCounterSolutions($data)
{
    try {
        $ch = curl_init();
        $curl_info = getWorkspaceCurlCounterSolutionsUrl();
        $url = $curl_info['url'];
        $api_signature = $curl_info['api_signature'];

        // Prepare JSON payload
        $payload = json_encode([["data" => $data, "api_signature" => $api_signature]]);

        // Set cURL options
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'Accept: application/json'
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Execute cURL request
        $result = curl_exec($ch);

        // Handle cURL errors
        if ($result === false) {
            echo json_encode(["status" => 0, "error" => "cURL error: " . curl_error($ch)]);
            die();
        }

        // Decode API response
        $decodedData = json_decode($result, true);
        curl_close($ch);

        // Handle API errors
        if (isset($decodedData['error'])) {
            echo json_encode(["status" => 0, "error" => "API Error: " . $decodedData['error']]);
            die();
        }

        return $decodedData;
    } catch (Exception $e) {
        echo json_encode(["status" => 0, "error" => "Exception: " . $e->getMessage()]);
        die();
    }
}



function getWorkspaceCurlCounterSolutionsUrl()
{
  $url = $GLOBALS['curl_url_api_console_rejoice_solutions'].'resources/lib/mail_sms_counter/curl_workspace_counter_solutions.php';

  return array('url' => $url, 'api_signature' => 'WR5yGWg6mZ');
}
