<?php
if (!function_exists('sendSMS')){

    /**
     * Send SMS
     * @return mixed
     */
    function sendSMS(string $to, string $message)
    {
        if(!$to){
            return false;
        }

        $re = '/^([0|\+[0-9]{1,5})?([0-9]{9})$/';
        preg_match($re, $to, $matches);
        // var_dump($to, $matches);
        if($matches && $matches[2]) {
            $basicAuthUserName = 'saleh@moneyloop.sa'; // The username to use with basic authentication
            $basicAuthPassword = '1Billion$'; // The password to use with basic authentication

            $client = new \UnifonicNextGenLib\UnifonicNextGenClient($basicAuthUserName, $basicAuthPassword);
            $rest = $client->getRest();
            $appSid = 'w9uVS4DTemDvMCkMMIikgZmM5NYWUz';
            $senderID = 'MoneyLoop';
            $body = $message;
            $recipient = '966'.$matches[2];
            $responseType = 'responseType';
            $correlationID = 'CorrelationID';
            $baseEncode = true;
            $statusCallback = 'statusCallback';
            $async = false;

            $result = $rest->createSendMessage($appSid, $senderID, $body, $recipient);
            // dd($result);
        }
    }
}
?>
