package model;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.util.ArrayList;

/**
 * Created by Gondr on 5/04/2017.
 */
public class Route {

    private String name;
    private transient ObservableList<Stop> stops;
    private ArrayList<Stop> serialisedStops;

    public Route(String name, ObservableList<Stop> stops){
        this.name = name;
        this.stops = FXCollections.observableArrayList(stops);
    }

    public void serialise(){
        serialisedStops = new ArrayList<>(stops);
    }

    public void deserialise(){
        stops = FXCollections.observableArrayList(serialisedStops);
    }

    public String getName() {
        return name;
    }

    public ObservableList<Stop> getStops() {
        return stops;
    }

    public boolean equals(Route route){
        if (this.name != route.getName()){
            if (this.getStops().equals(route.getStops())){
                //if the yhave a equivalent route somewhere.
                return true;
            }
            return false;
        }
        return true;
    }

    @Override
    public Route clone(){
        ObservableList<Stop> stopObservableList = FXCollections.observableArrayList();
        for (Stop stop: stops){
            stopObservableList.add(stop.clone());
        }
        Route route = new Route(this.name, stopObservableList);
        return route;
    }

    public String toString(){
        return this.name;
    }
}
