<?php

namespace App\Http\Controllers\Services;

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

class servicePrimeSmsController extends Controller
{
    public static function send($phone, $message)
    {

        $phone = ltrim($phone, '+');
        if (substr($phone, 0, 2) !== '88') {
            $phone = '88' . $phone;
        }

        $apiKey = setting('SMS_API_KEY_PRIME_SOFT_SMS');
        $smsType = setting('SMS_API_TYPE_PRIME_SOFT_SMS');
        $smsContent = urlencode($message);
        $masking = setting('SMS_API_SENDER_ID_PRIME_SOFT_SMS');
        $apiUrl = $masking
            ? "http://primesoft.bd24.top/smsapi/masking?api_key=$apiKey&smsType=$smsType&maskingID=$masking&mobileNo=$phone&smsContent=$smsContent"
            : "http://primesoft.bd24.top/smsapi/non-masking?api_key=$apiKey&smsType=$smsType&mobileNo=$phone&smsContent=$smsContent";

        $response = file_get_contents($apiUrl);
        if($response == '1003' || $response == 1003){
            return [
                'status' => false,
                'message' => 'Invalid API Key'
            ];
        } else{
            return [
                'status' => true,
                'message' => 'SMS sent successfully'
            ];
        }
        return $response;
    }
}
