<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreServiceEnquiryRequest;
use App\Mail\NewServiceEnquiryMail;
use App\Models\ServiceEnquiry;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class ServiceEnquiryController extends Controller
{
    /**
     * @param  StoreServiceEnquiryRequest  $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(StoreServiceEnquiryRequest $request): \Illuminate\Http\RedirectResponse
    {
        $serviceEnquiry = ServiceEnquiry::create($request->validated());

        Mail::to(env('ADMIN_EMAIL_ADDRESS'))->send(new NewServiceEnquiryMail($serviceEnquiry));

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