<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CardController extends Controller
{
    public function addPassenger(Request $request)
    {
        $request->merge([
            "is_child"=>$request->is_child=="false"?false:true
        ]);
        $validation = [
            'firstName' => 'required|max:255|min:3',
            'lastName' => 'required|max:255|min:3',
            'gender' => 'required|max:255',
            'nationality' => 'required|max:255',
            'passport' => 'required|max:255|min:3',
            'birth_date' => 'required',
            'place_of' => 'required',
            'expiry_date' => 'required',
            'passport_file' => 'required',
            'is_child'=>'nullable|boolean',
            'pcrneg'=>'nullable',
            'vacc1n_name'=>'nullable',
            'vacc1n_date' =>'nullable',
            'vacc2n_name'=>'nullable',
            'vacc2n_date'=>'nullable'
        ];
        if(!$request->is_child){
            $validation = array_merge($validation,[
                 'called' => 'required|max:255',
                 'phone' => 'required',
            ]);
        }
        $data = $request->validate($validation);
        
        $data['passport_file'] = $request->passport.'.'.$request->passport_file->extension();  
        $request->passport_file->move(public_path('uploads/passport'), $data['passport_file']);
        
        $request->session()->push('card.passengers', $data);
        
        return $data;
        
    }
}
