using FastEndpoints;
using Knots.DTO.User;
using Microsoft.EntityFrameworkCore;

namespace Knots.Endpoints.User;

public class DeleteUserEndpoint(KnotsDbContext db, AutoMapper.IMapper mapper) : Endpoint <DeleteUserDto>
{
    public override void Configure()
    { 
        Delete ("/users/{@Id}");
    }

    public override async Task HandleAsync(DeleteUserDto req, CancellationToken ct)
    {
        Models.User? user = mapper.Map<Models.User>(req);
        db.Users.Add(user);
        await db.SaveChangesAsync(ct);
        await Send.NoContentAsync(ct);
    }
}