using Brizco.Common.Models.Exception;

namespace Brizco.Identity.Api.Services;

public class UserService : IUserService
{
    private readonly UserManager<ApplicationUser> _userManager;

    public UserService(UserManager<ApplicationUser> userManager)
    {
        _userManager = userManager;
    }

    public async Task<List<ApplicationUser>> GetUsersAsync(CancellationToken cancellationToken)
    {
        var res = await _userManager.CreateAsync(new ApplicationUser
        {
            Email = StringExtensions.GetId(8),
            UserName = StringExtensions.GetId(9),

        });
        if (!res.Succeeded)
        {
            throw new AppException(res.Errors.ToString());
        }
        return await _userManager.Users.ToListAsync(cancellationToken);
    }
}