<?php

namespace App\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use App\Mail\MailNotify;
use App\Mail\MailNotifyAr;

use illuminate\contract\Mailer;
use Illuminate\Support\Facades\Mail;
use Validator;

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

        $validator = Validator::make($request->all(), [
            'first_name' => 'required',
            'last_name' => 'required',
            'email' => 'required',
            'university_name' => 'required',
            'program_name' => 'required',
            'program_costs' => 'required',
            'application_fees' => 'required',
            'application_number' => 'required',
            'web_version_language' => 'required',
        ]);


        if ($validator->fails()) {
            return response()->json(['error'=>$validator->errors()], 401);
        }
        $data=[
            'subject'=>'test subject',
            'body'=>'Hello this is test',
            'first_name'=>$request['first_name'],
            'last_name'=>$request['last_name'],
            'university_name'=>$request['university_name'],
            'program_name'=>$request['program_name'],
            'program_costs'=>$request['program_costs'],
            'application_fees'=>$request['application_fees'],
            'application_number'=>$request['application_number'],
            'web_version_language'=>$request['web_version_language'],
        ];
        try {
            if($request['web_version_language'] == 'EN'){
                Mail::to($request['email'])->send(new MailNotify($data));
            }
            if($request['web_version_language'] == 'AR'){
                Mail::to($request['email'])->send(new MailNotifyAr($data));

            }
                return response()->json(['Greate check your Email']);
        } catch(Exception $th){
            return response()->json(['sorry somthing went wrong']);

        }
    }

    public function create(Request $request)
    {
        //
        $validator = Validator::make($request->all(), [
            'name' => 'required'




        ]);

        if ($validator->fails()) {
            return response()->json(['error'=>$validator->errors()], 401);
        }
        $input = $request->all();
        $data=$input;
        try {
            Mail::to('manhesham86@gmail.com')->send(new MailNotify($data));
           return response()->json(['Greate check your Email']);
       } catch(Exception $th){
           return response()->json(['sorry sonthing went wrong']);

       }

        // dd($input);
        // $category = category::create($input);

    }
}
