package dev.service;

import dev.dao.UserDao;
import dev.database.DatabaseConnection;
import dev.model.OrderDetail;
import dev.model.User;

import java.sql.*;
import java.util.Objects;

public class AuthService {

    UserDao userDao = new UserDao();

    public boolean register(String username, String password, String email) {

        // TODO:
        // Validate and register user

        User user = userDao.findByUsername(username);
        if (user == null) {
            return userDao.save(new User(-1, username, password, email));
        }
        else System.out.println("Username already exists.");
        return false;
    }

    public User login(String username, String password) {

        // TODO:
        // Authenticate user
        User user = userDao.findByUsername(username);

        if (user == null) System.out.println("Username was not found.");

        return user;
    }

}