<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Modules\Twilio\Services\TwilioServiceInterface;

class SendTwilioSMSTest extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'twilio:test';
    protected $signature = 'twilio:test {number} {message?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send Twilio SMS Test (Legacy command - use twilio:test-sms instead)';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(TwilioServiceInterface $twilioService)
    {
        $this->warn('This command is deprecated. Use "twilio:test-sms" instead.');

        $message = $this->argument('message') ?? "Testing message. Lorem Ipsum Blah de Blah Test";
        $sendTo = $this->argument('number');

        $this->info('Testing Twilio SMS (Legacy method)');
        $this->line('Phone Number: ' . $sendTo);
        $this->line('Message: ' . $message);

        $result = $twilioService->testSMS($sendTo, $message);

        if ($result['success']) {
            $this->info('SMS sent successfully!');
            $this->line('Message SID: ' . $result['message_sid']);
            $this->line('Status: ' . $result['status']);
            return 0;
        } else {
            $this->error('Failed to send SMS: ' . ($result['error'] ?? 'Unknown error'));
            return 1;
        }
    }
}
