<?php
namespace App\Http\Controllers\Patient;
use App\Http\Controllers\Controller;
use App\Models\PatientNotification;

class NotificationController extends Controller
{
    public function index()
    {
        $notifications = PatientNotification::where('patient_id', session('patient_id'))
            ->latest()->paginate(20);

        // تحديد الكل كمقروء
        PatientNotification::where('patient_id', session('patient_id'))
            ->where('is_read', false)->update(['is_read'=>true,'read_at'=>now()]);

        return view('patient.notifications.index', compact('notifications'));
    }

    public function markRead($id)
    {
        PatientNotification::where('patient_id', session('patient_id'))
            ->findOrFail($id)->markRead();
        return back();
    }

    public function readAll()
    {
        PatientNotification::where('patient_id', session('patient_id'))
            ->where('is_read', false)
            ->update(['is_read'=>true,'read_at'=>now()]);
        return back()->with('success', 'تم تحديد الكل كمقروء');
    }
}
