package dev.service;

import dev.dao.UserDao;
import dev.model.User;

public class AuthService {

    private final UserDao userDao = new UserDao();

    public AuthService(UserDao userDao) {}

    public boolean register(String username, String password, String email) {
        String hashedPassword = Integer.toHexString(password.hashCode());
        User user = new User(0, username, hashedPassword, email);

        return userDao.save(user);
    }

    public User login(String username, String password) {
        User user = userDao.findByUsername(username);

        if (user != null ){
            String hashedInput = Integer.toHexString(password.hashCode());
            if (user.getPassword().equals(hashedInput)){
                return user;
            }
        }
        return null;
    }
}