<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

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

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

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

        $notification->forceDelete();

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