package com.ibtp.kontor.tradingcards;

import com.ibtp.kontor.dal.DatabaseManager;
import com.ibtp.kontor.tradingcards.dal.TeamImpl;
import com.ibtp.kontor.tradingcards.entity.TeamEntity;
import com.ibtp.kontor.util.LocalTestDatabase;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.ibtp.kontor.tradingcards.dal.SportImpl;
import com.ibtp.kontor.tradingcards.entity.SportEntity;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Collection;
import java.util.Iterator;

/**
 * Created by TPEETZ on 27.01.2015.
 */
public class CollectionTest {

    @BeforeAll
    public static void setUp() {
        DatabaseManager.setDatabase(new LocalTestDatabase());
        setupSports();
    }

    public static void setupSports() {
        SportImpl sportImpl = new SportImpl();
        SportEntity football = sportImpl.addSport("Football");
        setupFootballTeams(football);
        SportEntity baseball = sportImpl.addSport("Baseball");
        setupFootballTeams(baseball);
        SportEntity basketball = sportImpl.addSport("Basketball");
        setupBasketballTeams(basketball);
        SportEntity hockey = sportImpl.addSport("Hockey");
        setupHockeyTeams(hockey);
    }

    public static void setupFootballTeams(SportEntity football) {
        TeamImpl teamImpl = new TeamImpl();
        teamImpl.addTeam("Dallas Cowboys", football);
        teamImpl.addTeam("New York Giants", football);
        teamImpl.addTeam("Philadelphia Eagles", football);
        teamImpl.addTeam("Arizona Cardinals", football);
        teamImpl.addTeam("Washington Redskins", football);
        teamImpl.addTeam("Detroit Lions", football);
        teamImpl.addTeam("Minnesota Vikings", football);
        teamImpl.addTeam("Green Bay Packers", football);
        teamImpl.addTeam("Chicago Bears", football);
        teamImpl.addTeam("Tampa Bay Buccaneers", football);
        teamImpl.addTeam("San Francisco 49ers", football);
        teamImpl.addTeam("New Orleans Saints", football);
        teamImpl.addTeam("Atlanta Falcons", football);
        teamImpl.addTeam("Los Angeles Rams", football);
        teamImpl.addTeam("Buffalo Bills", football);
        teamImpl.addTeam("Miami Dolphins", football);
        teamImpl.addTeam("New York Jets", football);
        teamImpl.addTeam("New England Patriots", football);
        teamImpl.addTeam("Indianapolis Colts", football);
        teamImpl.addTeam("Houston Oilers", football);
        teamImpl.addTeam("Pittsburgh Steelers", football);
        teamImpl.addTeam("Cleveland Browns", football);
        teamImpl.addTeam("Kansas City Chiefs", football);
        teamImpl.addTeam("Los Angeles Raiders", football);
        teamImpl.addTeam("Denver Broncos", football);
        teamImpl.addTeam("San Diego Chargers", football);
        teamImpl.addTeam("Seattle Seahawks", football);
        teamImpl.addTeam("Jacksonville Jaguars", football);
        teamImpl.addTeam("Houston Texans", football);
    }

    public static void setupBaseballTeams(SportEntity baseball) {
        TeamImpl teamImpl = new TeamImpl();
    }

    public static void setupBasketballTeams(SportEntity basketball) {
        TeamImpl teamImpl = new TeamImpl();
        teamImpl.addTeam("Houston Rockets", basketball);
        teamImpl.addTeam("San Antonio Spurs", basketball);
        teamImpl.addTeam("Utah Jazz", basketball);
        teamImpl.addTeam("Denver Nuggets", basketball);
        teamImpl.addTeam("Minnesota Timberwolves", basketball);
        teamImpl.addTeam("Dallas Mavericks", basketball);
        teamImpl.addTeam("Seattle SuperSonics", basketball);
        teamImpl.addTeam("Phoenix Suns", basketball);
        teamImpl.addTeam("Golden State Warriors", basketball);
        teamImpl.addTeam("Portland Trail Blazers", basketball);
        teamImpl.addTeam("Los Angeles Lakers", basketball);
        teamImpl.addTeam("Sacramento Kings", basketball);
        teamImpl.addTeam("Los Angeles Clippers", basketball);
        teamImpl.addTeam("New York Knicks", basketball);
        teamImpl.addTeam("Orlando Magic", basketball);
        teamImpl.addTeam("New Jersey Nets", basketball);
        teamImpl.addTeam("Miami Heat", basketball);
        teamImpl.addTeam("Boston Celtics", basketball);
        teamImpl.addTeam("Philadelphia 76ers", basketball);
        teamImpl.addTeam("Washington Bullets", basketball);
        teamImpl.addTeam("Atlanta Hawks", basketball);
        teamImpl.addTeam("Chicago Bulls", basketball);
        teamImpl.addTeam("Indiana Pacers", basketball);
        teamImpl.addTeam("Cleveland Cavaliers", basketball);
        teamImpl.addTeam("Charlotte Hornets", basketball);
        teamImpl.addTeam("Detroit Pistons", basketball);
        teamImpl.addTeam("Milwaukee Bucks", basketball);
    }

    public static void setupHockeyTeams(SportEntity hockey) {
        TeamImpl teamImpl = new TeamImpl();
        teamImpl.addTeam("New York Rangers", hockey);
        teamImpl.addTeam("Buffalo Sabers", hockey);
        teamImpl.addTeam("Detroit Red Wings", hockey);
        teamImpl.addTeam("Vancouver Canucks", hockey);
        teamImpl.addTeam("Mighty Ducks of Anaheim", hockey);
        teamImpl.addTeam("Calgary Flames", hockey);
        teamImpl.addTeam("Edmonton Oilers", hockey);
        teamImpl.addTeam("Los Angeles Kings", hockey);
        teamImpl.addTeam("San Jose Sharks", hockey);
        teamImpl.addTeam("Chicago Blackhawks", hockey);
        teamImpl.addTeam("Dallas Stars", hockey);
        teamImpl.addTeam("St. Louis Blues", hockey);
        teamImpl.addTeam("Toronto Maple Leafs", hockey);
        teamImpl.addTeam("Winnipeg Jets", hockey);
        teamImpl.addTeam("Boston Bruins", hockey);
        teamImpl.addTeam("Hartford Whalers", hockey);
        teamImpl.addTeam("Montreal Canadiers", hockey);
        teamImpl.addTeam("Ottawa Senators", hockey);
        teamImpl.addTeam("Pittsburgh Penguins", hockey);
        teamImpl.addTeam("Quebec Nordiques", hockey);
        teamImpl.addTeam("Florida Panthers", hockey);
        teamImpl.addTeam("New Jersey Devils", hockey);
        teamImpl.addTeam("New York Islanders", hockey);
        teamImpl.addTeam("Philadelphia Flyers", hockey);
        teamImpl.addTeam("Tamba Bay Lightning", hockey);
        teamImpl.addTeam("Washington Capitals", hockey);
    }

    @AfterAll
    public static void tearDown() {
        TeamImpl teamImpl = new TeamImpl();
        Collection<TeamEntity> teamEntities = teamImpl.findAll();
        for (TeamEntity teamEntity : teamEntities) {
            teamImpl.delete(teamEntity);
        }
        SportImpl sportImpl = new SportImpl();
        Collection<SportEntity> sportEntities = sportImpl.findAll();
        for (SportEntity sportEntity : sportEntities) {
            sportImpl.delete(sportEntity);
        }
    }

    @Test
    public void gettAllSports() {
        SportImpl sportImpl = new SportImpl();
        Collection<SportEntity> resultList = sportImpl.findAll();
        assertEquals(4, resultList.size());
    }

    @Test
    public void getAllTeams() {
        TeamImpl teamImpl = new TeamImpl();
        Collection<TeamEntity> resultList = teamImpl.findAll();
        assertEquals(111, resultList.size());
    }
}
