using FastEndpoints;
using Knots.DTO.Role;

namespace Knots.Endpoints.Role;

public class DeleteRoleEndpoint(KnotsDbContext db, AutoMapper.IMapper mapper) : Endpoint<DeleteRoleDto>
{
    public override void Configure()
    {
        Delete("/roles");
        AllowAnonymous();
    }
    
    public override async Task HandleAsync(DeleteRoleDto req, CancellationToken ct)
    {
        Models.Role? role = mapper.Map<Models.Role>(req);
        db.Roles.Remove(role);
        await db.SaveChangesAsync(ct);
        await Send.NoContentAsync(ct);
    }
}