<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreSoumissionRequest;
use App\Mail\NouvelleSoumission;
use App\Models\Soumission;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Mail;

class ContactController extends Controller
{
    public function store(StoreSoumissionRequest $request, string $locale): RedirectResponse
    {
        $soumission = Soumission::create([
            ...$request->safe()->only(['sub_prenom', 'sub_nom', 'sub_email', 'sub_tel', 'sub_profil', 'sub_projet']),
            'sub_locale' => $locale,
        ]);

        Mail::to(config('mail.contact_to'))->queue(new NouvelleSoumission($soumission));

        return redirect()
            ->route('home', ['locale' => $locale])
            ->with('contact_success', true)
            ->withFragment('contact');
    }
}
