<?php

namespace App\Http\Controllers;

use App\Models\Notificacion;

class NotificationController extends Controller
{
    /**
     * Get recent notifications for the authenticated user (or general system).
     */
    public function index()
    {
        return response()->json(
            Notificacion::with('caso:id,numero_reclamo')
                ->latest()
                ->take(20)
                ->get()
        );
    }

    /**
     * Mark a specific notification as read.
     */
    public function markAsRead(Notificacion $notificacion)
    {
        $notificacion->update(['leida' => true]);

        return response()->json(['success' => true]);
    }

    /**
     * Mark all notifications as read.
     */
    public function markAllAsRead()
    {
        Notificacion::where('leida', false)->update(['leida' => true]);

        return response()->json(['success' => true]);
    }
}
