<?php

namespace App\Http\Controllers\Services;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class serviceBulkSMSbdController extends Controller
{
    public static function sendSms($phone, $message)
    {
        
        $url = setting('SMS_API_URL_BULKSMSBD') ?? 'http://bulksmsbd.net/api/smsapi';
        $api_key = setting('SMS_API_KEY_BULKSMSBD');
        $senderid = setting('SMS_API_SENDER_ID_BULKSMSBD');
        $number = $phone;
        
        $data = [
            "api_key" => $api_key,
            "senderid" => $senderid,
            "number" => $number,
            "message" => $message
        ];
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $response_get = curl_exec($ch);
        $response = json_decode($response_get, true);
    
        if($response['response_code'] == 202 || $response['response_code'] == 200){
            return [
                'status' => true,
                'message' => 'SMS sent successfully'
            ];
        }else{
            return [
                'status' => false,
                'message' => $response['error_message']
            ];
        } 
    }
}
