using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SIGCM.Infrastructure.Repositories;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class NotificationsController : ControllerBase
{
  private readonly NotificationRepository _repo;
  public NotificationsController(NotificationRepository repo) => _repo = repo;

  [HttpGet]
  public async Task<IActionResult> GetMyNotifications()
  {
    var userId = int.Parse(User.FindFirst("Id")?.Value!);
    var notifications = await _repo.GetByUserAsync(userId);
    var unreadCount = await _repo.GetUnreadCountAsync(userId);
    return Ok(new { items = notifications, unreadCount });
  }

  [HttpPut("{id}/read")]
  public async Task<IActionResult> MarkAsRead(int id)
  {
    await _repo.MarkAsReadAsync(id);
    return Ok();
  }
}