package controllers;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextField;
import model.ButtonSets;
import model.ButtonTypes;
import model.SceneCode;
import model.Stop;

import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;

/**
 * Created by Gondr on 5/04/2017.
 */
public class AddStopsController extends Controller{

    @FXML
    TextField stopAddress;

    public void addStop() throws Exception {
        Stop stop = new Stop(stopAddress.getText());
        if(parent.getSession().getDataManager().addStop(stop) == true){
            Optional<ButtonType> result = popUp(Alert.AlertType.CONFIRMATION, "Success!", "Stop has been successfully added.", "Would you like to add another stop?", ButtonSets.YesNo);
            if (result.get() == ButtonTypes.No){
                changeScene(SceneCode.MY_STOPS);
            } else{
                stopAddress.setText("");
            }
        }else{
            popUp(Alert.AlertType.WARNING, "Warning!", "Duplicate Entry", "You cannot add a duplicate stop.");
        }
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}
