<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Services\TwilioService;

class SmsTestController extends Controller
{
    public function showTestForm()
    {
        return view('sms.test');
    }

    public function sendTest(Request $request, TwilioService $twilio)
    {
        $request->validate([
            'phone' => 'required',
            'message' => 'required|string|max:160'
        ]);

        $result = $twilio->sendSms($request->phone, $request->message);

        if (!empty($result['success']) && $result['success']) {
            return back()->with('success', 'Test SMS sent successfully! SID: ' . ($result['message_sid'] ?? ''));
        }

        return back()->with('error', 'Failed to send SMS: ' . ($result['error'] ?? 'unknown'));
    }
}
