package seng302.Mock;

import seng302.GPSCoordinate;
import seng302.Model.Boat;
import seng302.Model.Leg;
import seng302.Model.Marker;
import seng302.RaceDataSource;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Observable;

/**
 * Created by jjg64 on 21/04/17.
 */
public class StreamedCourse extends Observable implements RaceDataSource {
    private StreamedCourseXMLReader streamedCourseXMLReader = null;
    private BoatXMLReader boatXMLReader = null;
    private RegattaXMLReader regattaXMLReader = null;
    private double windDirection = 0;

    public StreamedCourse() {}

    public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
        this.boatXMLReader = boatXMLReader;
        if (streamedCourseXMLReader != null && boatXMLReader != null) {
            this.boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());

            boatXMLReader.read();
        }
        setChanged();
        notifyObservers();
    }

    public StreamedCourseXMLReader getStreamedCourseXMLReader() {
        return streamedCourseXMLReader;
    }

    public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
        this.streamedCourseXMLReader = streamedCourseXMLReader;
        if (streamedCourseXMLReader != null && boatXMLReader != null) {
            boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
            boatXMLReader.read();
        }
    }

    public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
        this.regattaXMLReader = regattaXMLReader;
        setChanged();
        notifyObservers();
    }

    public void setWindDirection(double windDirection) {
        this.windDirection = windDirection;
    }

    public double getWindDirection() {
        return windDirection;
    }

    public boolean hasReadRegatta() { return regattaXMLReader != null; }

    public boolean hasReadBoats() { return boatXMLReader != null; }

    public boolean hasReadCourse() { return streamedCourseXMLReader != null; }

    public String getRegattaName() { return regattaXMLReader.getRegattaName(); }

    public List<Boat> getBoats() {
        return boatXMLReader.getBoats();
    }

    public List<Leg> getLegs() {
        return streamedCourseXMLReader.getLegs();
    }

    public List<Marker> getMarkers() { return streamedCourseXMLReader.getMarkers(); }

    public List<GPSCoordinate> getBoundary() {
        return streamedCourseXMLReader.getBoundary();
    }

    public ZonedDateTime getZonedDateTime() {
        return streamedCourseXMLReader.getRaceStartTime();
    }

    public GPSCoordinate getMapTopLeft() {
        return streamedCourseXMLReader.getMapTopLeft();
    }

    public GPSCoordinate getMapBottomRight() {
        return streamedCourseXMLReader.getMapBottomRight();
    }
}
