<?php

// app/Services/PlivoSms.php
namespace App\Services;

use Illuminate\Support\Facades\Http;

class PlivoSms
{
    public function send(string $to, string $text): bool
    {
        $authId = config('services.plivo.auth_id');
        $authToken = config('services.plivo.auth_token');
        $from = config('services.plivo.from');

        $url = "https://api.plivo.com/v1/Account/{$authId}/Message/";

        $res = Http::withBasicAuth($authId, $authToken)
            ->asJson()
            ->post($url, [
                'src'  => $from,
                'dst'  => $to,             // E.164 e.g. +16045551234
                'text' => $text,
            ]);

        return $res->successful();
    }
}