# notifications_app/views.py
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect, get_object_or_404
from .models import Notification

@login_required
def notification_list(request):
    notifications = request.user.notifications.filter(is_archived=False)
    return render(request, "notifications_list.html", {"notifications": notifications})

@login_required
def notification_mark_read(request, pk):
    notification = get_object_or_404(Notification, pk=pk, recipient=request.user)
    notification.is_read = True
    notification.save()
    return redirect("notification_list")

@login_required
def notification_delete(request, pk):
    notification = get_object_or_404(Notification, pk=pk, recipient=request.user)
    notification.soft_delete()
    return redirect("notification_list")

@login_required
def notification_mark_all_read(request):
    request.user.notifications.update(is_read=True)
    return redirect("notification_list")
