<?php
namespace gateways;

class KAVEHNEGARGateway{

    public static function sendSMS($apiKey , $mobile , $pattern , $input_data) {
        $baseUrl = "https://api.kavenegar.com/v1/$apiKey/verify/lookup.json?receptor=$mobile";

        if (isset($input_data[0])) $baseUrl .= "&token=" . rawurlencode(str_replace(' ', '-', $input_data[0]));
        if (isset($input_data[1])) $baseUrl .= "&token2=" . rawurlencode(str_replace(' ', '-', $input_data[1]));
        if (isset($input_data[2])) $baseUrl .= "&token3=" . rawurlencode(str_replace(' ', '-', $input_data[2]));
        if (isset($pattern)) $baseUrl .= "&template=" . rawurlencode(str_replace(' ', '-', $pattern));
        
        // Set and execute CURL request
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $baseUrl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $response = curl_exec($ch);
        curl_close($ch);

        // 🟢 Return the response
        return $response;
    }

    public static function kavehnegar($api, $mobile, $bodyId, $code){
        
        $url = "https://api.kavenegar.com/v1/$api/verify/lookup.json?receptor=$mobile&token=$code&template=$bodyId";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);

    }
}
