package podaci;

import beans.Korisnik;
import beans.Telefon;
import java.util.HashMap;
import java.util.LinkedList;
import javax.faces.bean.ApplicationScoped;

@ApplicationScoped
public class DB {

    private static HashMap<String, LinkedList<Telefon>> mapaTelefona
            = new HashMap<String, LinkedList<Telefon>>();
    private static HashMap<String, Korisnik> mapaKorisnika
            = new HashMap<String, Korisnik>();

    static {

        mapaKorisnika.put("drasko", new Korisnik("drasko123", "Drazen", "Draskovic",
                "draskovic@etf.rs", null));
        mapaKorisnika.put("nbosko", new Korisnik("bosko123", "Bosko", "Nikolic",
                "nbosko@etf.rs", null));

        LinkedList<Telefon> telefoni1 = new LinkedList<Telefon>();
        telefoni1.add(new Telefon("Baka Smiljka", "011-111-111", false, 1));
        telefoni1.add(new Telefon("Sanja", "064-123-3333", true, 2));
        telefoni1.add(new Telefon("Dr Petrovic", "011-555-333", false, 3));
        telefoni1.add(new Telefon("Dekan", "063-202-2002", true, 4));

        mapaTelefona.put("drasko", telefoni1);

        LinkedList<Telefon> telefoni2 = new LinkedList<Telefon>();
        telefoni2.add(new Telefon("Zaki", "011/222222", false, 1));
        telefoni2.add(new Telefon("Cmilos", "060/223322", true, 2));
        telefoni2.add(new Telefon("Dekan", "063/2022002", true, 3));
        mapaTelefona.put("nbosko", telefoni2);
    }

    public static Korisnik findKorisnikByUsername(String username) {
        return mapaKorisnika.get(username);
    }

    public static LinkedList<Telefon> getTelefoniByUsername(String username) {
        return mapaTelefona.get(username);
    }

    public static boolean isKorisnik(String username, String password) {
        Korisnik k = mapaKorisnika.get(username);
        return (k != null) && k.getPassword().equals(password);
    }
}
