<?php

namespace App\Http\Controllers;

use App\Notifications\SupportRequestSubmitted;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;
use Inertia\Inertia;

class SupportFormController extends Controller
{
    public function view()
    {
        return Inertia::render('Contact/Support');
    }

    public function store(Request $request): RedirectResponse
    {
        $validated = $request->validate([
            'reason'  => ['required', 'string', 'in:bug_report,general_feedback,missing_data'],
            'message' => ['required', 'string', 'max:5000'],
        ]);

        Notification::route('mail', config('mail.support_address', 'hello@flightsgoneby.com'))
            ->notify(new SupportRequestSubmitted(
                name: $request->user()->name,
                email: $request->user()->email,
                reason: $validated['reason'],
                message: $validated['message'],
            ));

        return back()->with('success', 'Your message has been sent.');
    }
}
