<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreContactRequest;
use App\Mail\NewContactMail;
use App\Models\Contact;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Mail;

class ContactController extends Controller
{
    /**
     * @return View
     */
    public function index(): View
    {
        return view('contact');
    }

    /**
     * @param  StoreContactRequest  $request
     * @return RedirectResponse
     */
    public function store(StoreContactRequest $request)
    {
        $contact = Contact::query()->create($request->validated());

        Mail::to(env('NOVA_ADMIN_EMAIL_ADDRESS'))->send(new NewContactMail($contact));

        return redirect()->route('contact')->with('message', 'success!');
    }
}
