<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mail\EnglishTestMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator; // Add this line


class EnglishTestMailController extends Controller
{
    //
    public function index(Request $request)
    {

        $validator = Validator::make($request->all(), [
            'student_name' => 'required',
            'student_email' => 'required',
            'student_level' => 'required',
            'cert_number' => 'required',
        ]);

        if ($validator->fails()) {
            return response()->json(['error'=>$validator->errors()], 401);
        }


        $data=[
            'subject'=>'test subject',
            'body'=>'Hello this is test',
            'student_name'=>$request['student_name'],
            'student_email'=>$request['student_email'],
            'student_level'=>$request['student_level'],
            'cert_number'=>$request['cert_number']
        ];


        Mail::to($request['student_email'])->send(new EnglishTestMail($data));

        return 'Email sent with PDF attachment.';
    }

    public function view()
    {
        return view('emails/englishTest/englishTestCert');
    }
}
