using System.Security.Claims;
using JobsMedical.Web.Models;
using JobsMedical.Web.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace JobsMedical.Web.Pages.Me;

[Authorize]
public class NotificationsModel : PageModel
{
    private readonly NotificationService _svc;
    public NotificationsModel(NotificationService svc) => _svc = svc;

    public List<Notification> Items { get; private set; } = new();

    public async Task OnGetAsync()
    {
        var uid = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
        Items = await _svc.ListAsync(uid);     // capture read-state for display
        await _svc.MarkAllReadAsync(uid);      // opening the page clears the bell
    }
}
