<?php

namespace App\Http\Controllers\Api\System;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Notification;

class NotificationController extends Controller
{
    // 🔹 list notif user
    public function index()
    {
        return Notification::where('user_id', auth()->id())
            ->latest()
            ->paginate(10);
    }

    // 🔹 mark as read
    public function read($id)
    {
        $notif = Notification::findOrFail($id);

        $notif->update([
            'is_read' => 1,
            'read_at' => now()
        ]);

        return $notif;
    }

    // 🔹 mark all as read
    public function readAll()
    {
        Notification::where('user_id', auth()->id())
            ->update([
                'is_read' => 1,
                'read_at' => now()
            ]);

        return response()->json(['message'=>'all read']);
    }
}