<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Patient;
use App\Models\PatientPassport;
class patientPassportController extends Controller
{
    public function uploadPassport(Request $request){
        $jsondata = [];
        
        if($request->hasFile(key: 'upload_passport')){
            $file = $request->file(key: 'upload_passport');
            $passport =uniqid().str_ireplace(' ','-', $file->getClientOriginalName()); 
            $file->storeAs('crm/passport/', $passport);
            } else {
            $passport = null ; 
        } 
        
        $data = PatientPassport::create([
            
            'patient_id' =>$request->patient_id,
            'user_id'=>$request->user_id,
            'passport_file'=>isset($request->passport_file) ? $request->passport_file : null,
            'description'=>$request->description,
            'country'=>$request->country,
            'city'=>$request->city,
            'patient_embassy_name'=>$request->patient_embassy_name,
            'passport_number'=>$request->passport_number,
            'attandant_name'=>isset($request->attandant_name) ? implode(',',$request->attandant_name) : null,
            'attandant_embassy_name'=>isset($request->attandant_embassy_name) ? implode(',', $request->attandant_embassy_name) : null,
            'attandant_passport_number'=>isset($request->attandant_passport_number) ? implode(',',$request->attandant_passport_number) : null,
            'hospital_id'=>isset($request->hospital_id) ? $request->hospital_id : null,
            'appointment_date'=>isset($request->appointment_date) ? $request->appointment_date : null,
            'upload_passport'=>env('AWS_CLOUDFLARE_URL')."/crm/passport/$passport",
            'status'=>$request->status      
                               
        ]);
        return response()->json(['data'=>$data]);
    }
}