package org.academiadecodigo.enuminatti.helloworld.services;

import org.academiadecodigo.enuminatti.helloworld.models.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class UserService {

    Map<String, User> userMap;

    public UserService() {
        userMap = new HashMap<>();
    }

    public void addUser(User user) {
        userMap.put(user.getName(), user);
    }

    public List<User> getUserList() {
        return new ArrayList<>(userMap.values());
    }

    public boolean authenticate(String name, String password) {
        if (name == null || password == null || !userMap.containsKey(name)) {
            return false;
        }

        return password.equals(userMap.get(name).getPassword());
    }
}
