using BlogPlatform.DTO.Comment.Request;
using BlogPlatform.DTO.Comment.Response;
using BlogPlatform.DTO.User.Request;
using BlogPlatform.DTO.User.Response;
using BlogPlatform.Models;
using FastEndpoints;
using PasswordGenerator;

namespace BlogPlatform.Endpoints.User;

public class CreateUserEndpoint(BlogPlatformDbContext db) : Endpoint<CreateUserDto,GetUserDto>
{
    public override void Configure()
    {
        Post("/api/users");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
    {
        string? salt = new Password()
            .IncludeLowercase()
            .IncludeUppercase()
            .IncludeNumeric()
            .IncludeSpecial()
            .LengthRequired(24)
            .Next();
        
        Models.User user = new()
        {
            Username = req.Username,
            Email = req.Email,
            Password = Singulink.Cryptography.PasswordHasher(req.Password+ salt, salt),
            Salt = salt,
            
        }
    }
}
