<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class NotificationController extends Controller
{
    /**
     * Display the user's notification page.
     */
    public function index(Request $request): View
    {
        return view('profile.notifications', [
            'user' => $request->user(),
            'notifications' => $request->user()->unreadNotifications,
        ]);
    }

    /**
     * Delete Notifcation
     */
    public function delete(Request $request): RedirectResponse
    {
        $request->validate([
            'id' => 'required|exists:notifications,id',
        ]);

        $notification = $request->user()
            ->notifications()
            ->where('id', $request->input('id'))
            ->firstOrFail();

        $notification->delete();

        return redirect()->back();
    }
}
