<?php

namespace App\Http\Controllers;

use App\Models\Patient;
use Illuminate\Http\Request;

class PatientQrController extends Controller
{
    public function scan($token)
    {
        // Find the patient with the secure token, scoped to companies or check tenancy manually
        $patient = Patient::where('secure_token', $token)->firstOrFail();

        // Enforce tenancy: only authorized company staff can access this profile
        $this->authorize('view', $patient);

        $patient->load(['visits.doctor', 'invoices']);

        return view('patients.scan-quick', compact('patient'));
    }
}
