<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\ApllyNowSubmission;
use App\Models\JoinTeamSubmission;
use App\Models\RequestInfoSubmission;


class FormController extends Controller
{
    public function applynow(Request $request)
    {

        $validated = $request->validate([
            'firstName' => 'required',
            'lastName' => 'required',
            'country' => 'required',
            'region' => 'required',
            'phone_number' => 'required',
            'email' => 'required|email',
            'message' => 'required',
        ]);

        $applyNowSubmission = ApllyNowSubmission::create([
            'firstName' => $validated['firstName'],
            'lastName' => $validated['lastName'],
            'country' => $validated['country'],
            'region' => $validated['region'],
            'phone_number' => $validated['phone_number'],
            'email' => $validated['email'],
            'message' => $validated['message'],
        ]);
        
        return redirect()->back()->with('success', 'Your application has been submitted!');
    }

    public function joinTeamSubmission(Request $request)
    {
        // dd($request->all());
        $validated = $request->validate([
            'name' => 'required',
            'surname' => 'required',
            'grade' => 'required',
            'section' => 'required',
            'phone_number' => 'required',
            'email' => 'required|email',
            'message' => 'required',
            'game_id' => 'required|exists:games,id',
        ]);

        $joinTeamSubmission = JoinTeamSubmission::create([
            'name' => $validated['name'],
            'surname' => $validated['surname'],
            'grade' => $validated['grade'],
            'section' => $validated['section'],
            'phone_number' => $validated['phone_number'],
            'email' => $validated['email'],
            'message' => $validated['message'],
            'game_id' => $validated['game_id'],
        ]);
        // dd($joinTeamSubmission);
        return redirect()->back()->with('success', 'Your team join request has been submitted!');
    }

    public function requestInfoSubmission(Request $request)
    {

        $validated = $request->validate([
            'firstName' => 'required',
            'lastName' => 'required',
            'country' => 'required',
            'region' => 'required',
            'phone_number' => 'required',
            'email' => 'required|email',
            'message' => 'required',
        ]);

        $requestInfoSubmission = RequestInfoSubmission::create([
            'firstName' => $validated['firstName'],
            'lastName' => $validated['lastName'],
            'country' => $validated['country'],
            'region' => $validated['region'],
            'phone_number' => $validated['phone_number'],
            'email' => $validated['email'],
            'message' => $validated['message'],
        ]);

        return redirect()->back()->with('success', 'Your information request has been submitted!');
    }
}