using Lactose.Context;
using Lactose.Models;

namespace Lactose.Repositories;

public class UserRepository(LactoseDbContext context) : IUserRepository {
    public void Dispose() => context.Dispose();

    public IEnumerable<User> GetAll() => context.Users.AsEnumerable();

    public void Insert(User user) => context.Users.Add(user);

    public void Save() => context.SaveChanges();

    public User? Find(Guid id) => context.Users.Find(id);

    public User? FindByEmail(string email) => context.Users.FirstOrDefault(u => u.Email == email);

    public User? FindByUsername(string username) => context.Users.FirstOrDefault(u => u.Username == username);

    public void Delete(User user) => context.Users.Remove(user);
}
