<?php

namespace App\Http\Controllers;

use App\Models\Notification;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

class NotificationController extends Controller
{
    public function index(): View
    {
        return view('trading.notifications', [
            'pageTitle' => 'Notifications',
            'pageSubtitle' => 'In-app alerts for trades and bot events',
            'notifications' => Notification::where('user_id', auth()->id())->latest()->paginate(20),
        ]);
    }

    public function markRead(Notification $notification): RedirectResponse
    {
        abort_unless($notification->user_id === auth()->id(), 403);
        $notification->update(['read_at' => now()]);

        return back();
    }
}
