package pl.minidmnv.apple.source.fixture.repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.jsoup.nodes.Document;

import org.jsoup.select.Elements;
import pl.minidmnv.apple.source.fixture.data.Fixture;
import pl.minidmnv.apple.source.fixture.repository.picker.FSFixtureDOMElementPicker;
import pl.minidmnv.apple.source.fixture.tray.FixtureTray;

/**
 * @author mnicinski.
 */
public class FlashScoreFixtureRepository implements FixtureRepository {

	private FixtureTray fixtureTray;
	private FSFixtureDOMElementPicker picker = new FSFixtureDOMElementPicker();

	@Override
	public List<Fixture> getUpcomingFixtures(Integer limit) {
		List fixtures = new ArrayList();
		Optional<Document> upcomingFixturesDocument = fixtureTray.getUpcomingFixturesDocument();

		if (upcomingFixturesDocument.isPresent()) {
			Document doc = upcomingFixturesDocument.get();
			picker.init(doc);
			fixtures = parseFixtures(doc);
		}

		return fixtures;
	}

	private List parseFixtures(Document document) {
		Elements elements = picker.pickUpcomingFixtures();
		return null;
	}
}

@@ -124,16 +124,52 @@
 ptional;
+%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -196,16 +196,48 @@
 ument;%0A%0A
+import org.jsoup.nodes.Element;%0A
 import o
@@ -972,28 +972,8 @@
 ();%0A
-%09%09%09picker.init(doc);
 %0A%09%09%09
@@ -1075,16 +1075,31 @@
  doc
-ument) %7B
+) %7B%0A%09%09picker.init(doc);
 %0A%09%09E
@@ -1148,16 +1148,17 @@
 ures();%0A
+%0A
 %09%09return
@@ -1162,12 +1162,241 @@
 urn 
-null
+elements.stream()%0A%09%09%09%09.map(this::transformStageScheduledElementToFixture)%0A%09%09%09%09.collect(Collectors.toList());%0A%09%7D%0A%0A%09private Fixture transformStageScheduledElementToFixture(Element e) %7B%0A%09%09Fixture result = new Fixture();%0A%0A%09%09return result
 ;%0A%09%7D

Prepare to supply fixtures from DOM elements