<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\TwilioService;

class TestTwilioConnection extends Command
{
    protected $signature = 'twilio:test {phone}';
    protected $description = 'Test Twilio SMS connection';

    public function handle(TwilioService $twilio)
    {
        $phone = $this->argument('phone');

        $this->info('Sending test SMS to: ' . $phone);

        $result = $twilio->sendSms($phone, 'Test SMS from Laravel Loan System');

        if (!empty($result['success']) && $result['success']) {
            $this->info('✅ SMS sent successfully!');
            $this->info('Message SID: ' . ($result['message_sid'] ?? ''));
        } else {
            $this->error('❌ Failed to send SMS: ' . ($result['error'] ?? 'unknown'));
        }
    }
}
