<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreReferralRequest;
use App\Mail\NewReferralMail;
use App\Models\Referral;
use Illuminate\Support\Facades\Mail;

class ReferController extends Controller
{
    /**
     * @return \Illuminate\View\View
     */
    public function index(): \Illuminate\View\View
    {
        return view('refer-offer');
    }

    /**
     * @param  StoreReferralRequest  $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(StoreReferralRequest $request): \Illuminate\Http\RedirectResponse
    {
        $referral = Referral::query()->create($request->validated());

        Mail::to(env('NOVA_ADMIN_EMAIL_ADDRESS'))->send(new NewReferralMail($referral));

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