package objects;

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

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.MapValueFactory;
import javafx.scene.control.cell.PropertyValueFactory;

@SuppressWarnings("rawtypes")
public class RaceTableRow implements Initializable {

	private String trackName;
	private String horseName;
	private String driverName;
	private int raceNumber;
	private int lane;
	private float avgDriverTime;
	private float avgHorseTime;
	private float avgDriverTimeByDistance;
	private float avgHorseTimeByDistance;
	private int distance;
	private String timeModifier;
	private int shoes;
	private String trainerName;
	private int result;
	private float avgTime;
	private float laneWin;
	private String horseGallopRate;
	private String driverGallopRate;

	@FXML TableColumn<Map, String> trackColumn = new TableColumn<>("Track");
	@FXML TableColumn<Map, Integer> raceColumn = new TableColumn<>("Race");
	@FXML TableColumn<Map, String> horseNameColumn = new TableColumn<>("Horse name");
	@FXML TableColumn<Map, Integer> laneColumn = new TableColumn<>("Lane");
	@FXML TableColumn<Map, Integer> distanceColumn = new TableColumn<>("Distance");
	@FXML TableColumn<Map, String> timeModifierColumn = new TableColumn<>("Time modifier");
	@FXML TableColumn<Map, String> driverNameColumn = new TableColumn<>("Driver name");
	@FXML TableColumn<Map, String> trainerNameColumn = new TableColumn<>("Trainer name");
	@FXML TableColumn<Map, Integer> resultColumn = new TableColumn<>("Result");
	@FXML TableColumn<Map, String> horseAvgTimeColumn = new TableColumn<>("Horse avg time");
	@FXML TableColumn<Map, String> horseAvgTimeDistanceColumn = new TableColumn<>("Horse avg time distance");
	@FXML TableColumn<Map, String> horseGallopRateColumn = new TableColumn<>("Horse gallop rate");
	@FXML TableColumn<Map, String> driverAvgTimeColumn = new TableColumn<>("Driver avg time");
	@FXML TableColumn<Map, String> driverAvgTimeDistanceColumn = new TableColumn<>("Driver Avg time distance");
	@FXML TableColumn<Map, String> driverGallopRateColumn = new TableColumn<>("Driver gallop rate");
	@FXML TableColumn<Map, Float> avgTimeColumn = new TableColumn<>("Avg time");
	@FXML TableColumn<Map, Float> calculationColumn = new TableColumn<>("Calculated Value");
	@FXML TableColumn<Map, String> laneWinColumn = new TableColumn<>("Lane win %");

	@FXML
	protected TableView<Map<String, Object>> racesTable;

	public RaceTableRow() {
		System.out.println("RaceTableRow");
		trackColumn.getTableView();
	}

	public RaceTableRow(HorseRaceData data) {
		trackName = data.getTrackName();
		horseName = data.getHorseName();
		driverName = data.getDriverName();
		raceNumber = data.getRaceNumber();
		lane = data.getLane();
		avgDriverTime = data.getAvgDriverTime();
		avgHorseTime = data.getAvgHorseTime();
		avgDriverTimeByDistance = data.getAvgDriverTimeByDistance();
		avgHorseTimeByDistance = data.getAvgHorseTimeByDistance();
		distance = data.getDistance();
		timeModifier = data.getTimeModifier();
		shoes = data.getShoes();
		trainerName = data.getTrainerName();
		result = data.getResult();

		//		racesTable.getColumns().add(0, trackColumn);
		updateTable();
	}

	private void updateTable() {
		trackColumn.setText(trackName);
	}

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		trackColumn.setCellValueFactory(new PropertyValueFactory<>("track"));// new MapValueFactory<>("track"));
		raceColumn.setCellValueFactory(new MapValueFactory<>("race"));
		horseNameColumn.setCellValueFactory(new MapValueFactory<>("horseName"));
		laneColumn.setCellValueFactory(new MapValueFactory<>("lane"));
		distanceColumn.setCellValueFactory(new MapValueFactory<>("distance"));
		timeModifierColumn.setCellValueFactory(new MapValueFactory<>("timeModifier"));
		driverNameColumn.setCellValueFactory(new MapValueFactory<>("driverName"));
		trainerNameColumn.setCellValueFactory(new MapValueFactory<>("trainerName"));
		resultColumn.setCellValueFactory(new MapValueFactory<>("result"));
		horseAvgTimeColumn.setCellValueFactory(new MapValueFactory<>("horseAvgTime"));
		horseAvgTimeDistanceColumn.setCellValueFactory(new MapValueFactory<>("horseAvgTimeDistance"));
		driverAvgTimeColumn.setCellValueFactory(new MapValueFactory<>("driverAvgTime"));
		driverAvgTimeDistanceColumn.setCellValueFactory(new MapValueFactory<>("driverAvgTimeDistance"));
		avgTimeColumn.setCellValueFactory(new MapValueFactory<>("avgTime"));
		calculationColumn.setCellValueFactory(new MapValueFactory<>("calculatedValue"));
		laneWinColumn.setCellValueFactory(new MapValueFactory<>("laneWin"));
		horseGallopRateColumn.setCellValueFactory(new MapValueFactory<>("horseGallopRate"));
		driverGallopRateColumn.setCellValueFactory(new MapValueFactory<>("driverGallopRate"));
	}


	public void setTrack(String trackName) {
		this.trackName = trackName;
		updateTable();
	}

	public String getTrackName() {
		return trackName;
	}

	public String getHorseName() {
		return horseName;
	}

	public String getDriverName() {
		return driverName;
	}

	public int getRaceNumber() {
		return raceNumber;
	}

	public int getLane() {
		return lane;
	}

	public float getAvgDriverTime() {
		return avgDriverTime;
	}

	public float getAvgHorseTime() {
		return avgHorseTime;
	}

	public float getAvgDriverTimeByDistance() {
		return avgDriverTimeByDistance;
	}

	public float getAvgHorseTimeByDistance() {
		return avgHorseTimeByDistance;
	}

	public int getDistance() {
		return distance;
	}

	public String getTimeModifier() {
		return timeModifier;
	}

	public int getShoes() {
		return shoes;
	}

	public String getTrainerName() {
		return trainerName;
	}

	public int getResult() {
		return result;
	}

	public void setTrackName(String trackName) {
		this.trackName = trackName;
	}

	public void setHorseName(String horseName) {
		this.horseName = horseName;
	}

	public void setDriverName(String driverName) {
		this.driverName = driverName;
	}

	public void setRaceNumber(int raceNumber) {
		this.raceNumber = raceNumber;
	}

	public void setLane(int lane) {
		this.lane = lane;
	}

	public void setAvgDriverTime(float avgDriverTime) {
		this.avgDriverTime = avgDriverTime;
	}

	public void setAvgHorseTime(float avgHorseTime) {
		this.avgHorseTime = avgHorseTime;
	}

	public void setAvgDriverTimeByDistance(float avgDriverTimeByDistance) {
		this.avgDriverTimeByDistance = avgDriverTimeByDistance;
	}

	public void setAvgHorseTimeByDistance(float avgHorseTimeByDistance) {
		this.avgHorseTimeByDistance = avgHorseTimeByDistance;
	}

	public void setDistance(int distance) {
		this.distance = distance;
	}

	public void setTimeModifier(String timeModifier) {
		this.timeModifier = timeModifier;
	}

	public void setShoes(int shoes) {
		this.shoes = shoes;
	}

	public void setTrainerName(String trainerName) {
		this.trainerName = trainerName;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public float getAvgTime() {
		return avgTime;
	}

	public void setAvgTime(float avgTime) {
		this.avgTime = avgTime;
	}

	public float getLaneWin() {
		return laneWin;
	}

	public void setLaneWin(float laneWin) {
		this.laneWin = laneWin;
	}

	public String getHorseGallopRate() {
		return horseGallopRate;
	}

	public String getDriverGallopRate() {
		return driverGallopRate;
	}

	public void setHorseGallopRate(String horseGallopRate) {
		this.horseGallopRate = horseGallopRate;
	}

	public void setDriverGallopRate(String driverGallopRate) {
		this.driverGallopRate = driverGallopRate;
	}

}
