using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

using Monitoring.Controllers;
using Monitoring.Infrastructure.Data;

namespace Monitoring.Features.RoleManagement;

[Route("/api/roles")]
public class RolesController(
	DataContext context
) : BaseController
{
	public record RoleModel(Guid Id, string Name, string UpperCaseName);

	[HttpGet(Name = "GetRoleList")]
	[AllowAnonymous]
	[ProducesResponseType<List<RoleModel>>(StatusCodes.Status200OK)]
	public async ValueTask<IActionResult> GetList(CancellationToken cancellationToken)
	{
		return Ok(
			await context.Roles
				.Select(x => new RoleModel(x.Id.Value, x.Name.Value, x.UpperCaseName.Value))
				.ToListAsync(cancellationToken)
		);
	}
}
