using Microsoft.EntityFrameworkCore;

using Monitoring.Core.Domain;
using Monitoring.Core.Domain.UserPrimitives;
using Monitoring.Infrastructure.Data;

namespace Monitoring.Repositories;

public class UserRepository(
	DataContext dataContext
)
{
	public Task<User?> Find(string username, CancellationToken cancellationToken)
	{
		var upperCaseUsername = UserUpperCaseName.Create(username);
		return dataContext.Users
			.FirstOrDefaultAsync(x => x.UpperCaseUsername == upperCaseUsername, cancellationToken);
	}

	public Task<User?> Get(UserId id, CancellationToken cancellationToken)
	{
		return dataContext.Users.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
	}
}