using API.DTO.Color.Request;
using API.DTO.Color.Response;
using FastEndpoints;

namespace API.Endpoints.Color;

public class CreateColorEndpoint(AppDbContext appDbContext) : Endpoint<CreateColorDto, GetColorDto>
{
    public override void Configure()
    {
        Post("/color/create");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CreateColorDto req, CancellationToken ct)
    {
        Models.Color color = new()
        {
            Label = req.Label,
        };
        
        appDbContext.Colors.Add(color);
        await appDbContext.SaveChangesAsync(ct);
        Console.WriteLine("Added Color");

        GetColorDto responseDto = new()
        {
            Id = color.Id,
            Label = req.Label,
        };

        await Send.OkAsync(responseDto, ct);
    }
    
}