/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.hogent.iii.voetbal.consoleapplicatie;

import be.hogent.iii.voetbal.bo.Doelpunt;
import be.hogent.iii.voetbal.bo.Kaart;
import be.hogent.iii.voetbal.bo.Match;
import be.hogent.iii.voetbal.bo.Wissel;
import be.hogent.iii.voetbal.interfaces.IClub;
import be.hogent.iii.voetbal.interfaces.IDataStorage;
import be.hogent.iii.voetbal.interfaces.IDoelpunt;
import be.hogent.iii.voetbal.interfaces.IKaart;
import be.hogent.iii.voetbal.interfaces.IMatch;
import be.hogent.iii.voetbal.interfaces.IPersoon;
import be.hogent.iii.voetbal.interfaces.IScheidsrechter;
import be.hogent.iii.voetbal.interfaces.IVoetballer;
import be.hogent.iii.voetbal.interfaces.IWissel;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *
 * @author kvdw
 */
public class Testprogramma {

    /**
     * @param args the command line arguments
     */
    
    private static void toonClub (IClub club) {
        System.out.println("Id :"+ club.getId());
        System.out.println("Naam :"+ club.getNaam());
        System.out.println("Clubkleuren :"+club.getClubkleuren());
        System.out.println("Logo :"+club.getLogo());
        System.out.println("Website :"+club.getWebsite());
        System.out.println("Stadion naam: "+club.getStadion().getNaam());
        System.out.println("Capaciteit :"+club.getStadion().getCapaciteit());
        System.out.println("Straat: "+club.getStadion().getStraat());
        System.out.println("Nummer: "+club.getStadion().getNummer());
        System.out.println("Naam gemeente: "+club.getStadion().getGemeenteNaam());
        System.out.println("Postcode :"+club.getStadion().getPostCode()+"\n");
    }
    
     private static void toonMatch(IMatch match) {
         System.out.println("ID :"+match.getId());
         System.out.println("Speeldag :"+match.getSpeeldag());
         System.out.println("Thuisploeg :"+match.getThuisploeg().getNaam());
         System.out.println("Uitploeg :"+match.getUitploeg().getNaam());
         System.out.println("Scheidsrechter :"+match.getScheidsrechter().getNaam());
         SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
         System.out.println("Datum :"+d.format(match.getDatum()));
         SimpleDateFormat h = new SimpleDateFormat("HH:mm");
         System.out.println("Uur :"+h.format(new Date(match.getTime().getTime())));
         System.out.println("Aantal toeschouwers :"+match.getAantalToeschouwers());
        
         System.out.println("Spelers thuisploeg :");
         
         for (IVoetballer voetballer : match.getThuisPloegSpelers()) {
             System.out.println(voetballer.getNaam());
         }
         
         
         System.out.println("Spelers uitploeg :");
         for (IVoetballer voetballer : match.getUitPloegSpelers()) {
             System.out.println(voetballer.getNaam());
         }
         System.out.println("Kaarten :");
         for (IKaart kaart : match.getKaarten()) {
             System.out.println(kaart.getVoetballer().getNaam()+" "+kaart.getKleur()+" "+kaart.getMinuut());
         }
         
         System.out.println("Doelpunten :");
         
         for (IDoelpunt doelpunt : match.getDoelpunten()) {
             System.out.println(doelpunt.getVoetballer().getNaam()+" "+doelpunt.getMinuut()+" "+(doelpunt.getOwngoal()?"owngoal":"goal"));
         }
         
         System.out.println("Wissels :");
         
         for (IWissel wissel : match.getWissels()) {
             System.out.println("In: "+wissel.getVoetballer().getNaam()+" Uit: "+wissel.getVoetballerIn().getNaam()+" "+wissel.getMinuut());
         }
    }

    private static void toonScheidsrechter(IPersoon scheidsrechter) {
        System.out.println("Id :"+scheidsrechter.getId());
        System.out.println("Naam :"+scheidsrechter.getNaam());
        System.out.println("Foto :"+scheidsrechter.getFoto());
        System.out.println("Nationaliteit :"+scheidsrechter.getNationaliteit()+"\n");
    }

    private static void toonVoetballer(IVoetballer voetballer) {
        toonScheidsrechter(voetballer);
        System.out.println("Positie :"+voetballer.getPositie());
        System.out.println("Clubs :");
        for (Map.Entry <Integer,List <IClub>> entry : voetballer.getClubs().entrySet()) {
            System.out.print("Jaartal: "+entry.getKey()+ " Clubs :");
            for (IClub club : entry.getValue()) {
                System.out.print(" "+club.getNaam());
            }
            System.out.println("\n");
        }
    }
    
    public static void main(String[] args) {
        // TODO code application logic here
        try {
            IDataStorage database = (IDataStorage) Class.forName("be.hogent.iii.voetbal.bo.JDBCDataStorage").newInstance();
            
            System.out.println("Lijst van clubs");

            for (IClub club : database.getClubs()) {
                toonClub(club);
            }

            System.out.println("Club ophalen dmv id");

            IClub club = database.getClub("STA");
            toonClub(club);

            System.out.println("Lijst van voetballers");

            for (IVoetballer voetballer : database.getVoetballers()) {
                toonVoetballer(voetballer);
            }

            System.out.println("Voetballer ophalen dmv id");

            IVoetballer voetballer = database.getVoetballer("JELLEVOSSEN");
            toonVoetballer(voetballer);

            System.out.println("Lijst van scheidsrechters");

            for (IScheidsrechter scheidsrechter : database.getScheidsrechters()) {
                toonScheidsrechter(scheidsrechter);
            }

            System.out.println("Scheidsrecher ophalen dmv id");

            IScheidsrechter scheidsrechter = database.getScheidsRechter("TIMPOTS");
            toonScheidsrechter(scheidsrechter);

            System.out.println("Lijst van matchen");

            for (IMatch match : database.getMatchen()) {
                toonMatch(match);
            }

            System.out.println("Match ophalen dmv id");

            IMatch match = database.getMatch(5);
            toonMatch(match);

            System.out.println("Match toevoegen");

            SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
            SimpleDateFormat u = new SimpleDateFormat("hh:mm");
            IClub thuisploeg = database.getClub("ZWA");
            IClub uitploeg = database.getClub("GBA");
            scheidsrechter = database.getScheidsRechter("GERDBYLOIS");

            List <IVoetballer> spelersthuis = new ArrayList<IVoetballer>();

            spelersthuis.add(database.getVoetballer("SAMMYBOSSUT"));
            spelersthuis.add(database.getVoetballer("KARELDHAENE"));
            spelersthuis.add(database.getVoetballer("STIJNMINNE"));
            spelersthuis.add(database.getVoetballer("BARTBUYSSE"));
            spelersthuis.add(database.getVoetballer("JÇ%RÇ%MYTARAVEL"));
            spelersthuis.add(database.getVoetballer("LUDWINVANNIEUWENHUYZE"));
            spelersthuis.add(database.getVoetballer("FRANCKBERRIER"));
            spelersthuis.add(database.getVoetballer("KEVINROELANDTS"));
            spelersthuis.add(database.getVoetballer("ERNESTNFOR"));
            spelersthuis.add(database.getVoetballer("TEDDYCHEVALIER"));
            spelersthuis.add(database.getVoetballer("CHRISMAKIESE"));
            spelersthuis.add(database.getVoetballer("STEVECOLPAERT"));
            spelersthuis.add(database.getVoetballer("KHALEEMHYLAND"));
            spelersthuis.add(database.getVoetballer("BERATSADIK"));

            List <IVoetballer> spelersuit = new ArrayList<IVoetballer>();

            spelersuit.add(database.getVoetballer("TOMISLAVPACOVSKI"));
            spelersuit.add(database.getVoetballer("PHILIPPECLEMENT"));
            spelersuit.add(database.getVoetballer("KURTVANDOOREN"));
            spelersuit.add(database.getVoetballer("PIETERJANMONTEYNE"));
            spelersuit.add(database.getVoetballer("MARTIJNMONTEYNE"));
            spelersuit.add(database.getVoetballer("BARTGOOR"));
            spelersuit.add(database.getVoetballer("WIMDEDECKER"));
            spelersuit.add(database.getVoetballer("FARISHAROUN"));
            spelersuit.add(database.getVoetballer("DANIELCRUZ"));
            spelersuit.add(database.getVoetballer("BAVONTSHIBUABUA"));
            spelersuit.add(database.getVoetballer("SHERJILLMACDONALD"));
            spelersuit.add(database.getVoetballer("MATSRITS"));
            spelersuit.add(database.getVoetballer("TOSINDOSUMNU"));

            List <IKaart> kaarten = new ArrayList<IKaart>();

            kaarten.add(new Kaart(database.getVoetballer("CHRISMAKIESE"), 46, "geel"));
            kaarten.add(new Kaart(database.getVoetballer("PIETERJANMONTEYNE"), 37, "geel"));
            kaarten.add(new Kaart(database.getVoetballer("BARTGOOR"), 70, "geel"));
            kaarten.add(new Kaart(database.getVoetballer("MATSRITS"), 75, "geel"));
            kaarten.add(new Kaart(database.getVoetballer("ERNESTNFOR"), 85, "geel"));
            kaarten.add(new Kaart(database.getVoetballer("WIMDEDECKER"), 86, "geel"));

            List <IDoelpunt> doelpunten = new ArrayList<IDoelpunt>();

            doelpunten.add(new Doelpunt(database.getVoetballer("TEDDYCHEVALIER"), 39, false));
            doelpunten.add(new Doelpunt(database.getVoetballer("KEVINROELANDTS"), 41, false));
            doelpunten.add(new Doelpunt(database.getVoetballer("CHRISMAKIESE"), 71, false));
            doelpunten.add(new Doelpunt(database.getVoetballer("TEDDYCHEVALIER"), 77, false));

            List <IWissel> wissels = new ArrayList<IWissel>();

            wissels.add(new Wissel(database.getVoetballer("JÇ%RÇ%MYTARAVEL"), 34, database.getVoetballer("STEVECOLPAERT")));
            wissels.add(new Wissel(database.getVoetballer("DANIELCRUZ"), 63, database.getVoetballer("MATSRITS")));
            wissels.add(new Wissel(database.getVoetballer("PHILIPPECLEMENT"), 70, database.getVoetballer("TOSINDOSUMNU")));
            wissels.add(new Wissel(database.getVoetballer("KEVINROELANDTS"), 88, database.getVoetballer("KHALEEMHYLAND")));
            wissels.add(new Wissel(database.getVoetballer("ERNESTNFOR"), 91, database.getVoetballer("BERATSADIK")));

            IMatch hulpmatch = new Match(-1, 11, d.parse("17/10/2009"), new Time((u.parse("18:00")).getTime()), 6417, thuisploeg, uitploeg, scheidsrechter, spelersthuis, spelersuit, kaarten, doelpunten, wissels);

            boolean resultaat = database.addMatch(hulpmatch);
            
            if (resultaat) {
                System.out.println("Het toevoegen van de match is gelukt");
            }
            else {
                System.out.println("Het toevoegen van de match is misluktS");
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }
    
}
