<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class NotificationController extends Controller
{
    public function index()
    {
        // Admin gets all notifications
        $user = auth()->user();
        if (!$user) return response()->json([]);

        $notifications = $user->unreadNotifications()->take(20)->get();
        return response()->json($notifications);
    }

    public function markAsRead()
    {
        $user = auth()->user();
        if ($user) {
            $user->unreadNotifications->markAsRead();
        }
        return response()->json(['status' => 'success']);
    }
}
