using JSMR.Application.Users;
using JSMR.Domain.Entities;
using Microsoft.EntityFrameworkCore;

namespace JSMR.Infrastructure.Data.Repositories.Users;

public class UserRepository(AppDbContext db) : IUserRepository
{
    public async Task<User?> FindByUsernameAsync(string username)
    {
        return await db.Users
            .FirstOrDefaultAsync(u => u.Username == username);
    }

    public bool VerifyPassword(User user, string password)
    {
        // Using BCrypt (recommended)
        return BCrypt.Net.BCrypt.Verify(password, user.PasswordHash);
    }
}