<?php

namespace App\Http\Controllers;

use App\Jobs\ProcessContactInquiryJob;
use App\Models\ContactInquiry;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class ContactInquiryController extends Controller
{
    public function store(Request $request): RedirectResponse
    {
        $data = $request->validate([
            'name' => 'required|string|max:120',
            'email' => 'required|email|max:180',
            'business_name' => 'nullable|string|max:180',
            'phone' => 'nullable|string|max:60',
            'message' => 'required|string|max:3000',
        ]);

        $inquiry = ContactInquiry::create($data + ['status' => 'queued']);
        ProcessContactInquiryJob::dispatch($inquiry->id);

        return back()->with('success', 'Inquiry queued successfully. The team will contact you shortly.');
    }
}
