<?php
/*
    Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

namespace GnuBoat;

/**
  * @brief One item in a track
  */
class TrackItem
{
	function __construct()
	{
		$this->_time = null;
		$this->_latitude = null;
		$this->_longitude = null;
		$this->_speedThroughWater = null;
		$this->_speedOverGround = null;
		$this->_courseOverGround = null;
		$this->_waterDepth = null;
		$this->_waterTemperature = null;
		$this->_gpsfix = null;
	}

	public function setTimestamp($time)
	{
		$this->_time = $time;
	}
	
	public function setDateTime($dateTime)
	{
		$timezone = new \DateTimeZone("UTC");
		if($dateTime == null)
			$this->_time = null;
		$dateTime->setTimezone($timezone);
		$this->_time = $dateTime->getTimestamp();
	}
	
	public function timestamp()
	{
		return $this->_time;
	}
	
		public function setLatitude($latitude)
	{
		$this->_latitude = $latitude;
	}
	
	public function latitude()
	{
		return $this->_latitude;
	}
	
		public function setLongitude($longitude)
	{
		$this->_longitude = $longitude;
	}
	
	public function longitude()
	{
		return $this->_longitude;
	}
	
		public function setSpeedThroughWater($speedThroughWater)
	{
		$this->_speedThroughWater = $speedThroughWater;
	}
	
	public function speedThroughWater()
	{
		return $this->_speedThroughWater;
	}
	
		public function setSpeedOverGround($speedOverGround)
	{
		$this->_speedOverGround = $speedOverGround;
	}
	
	public function speedOverGround()
	{
		return $this->_speedOverGround;
	}
	
		public function setCourseOverGround($courseOverGround)
	{
		$this->_courseOverGround = $courseOverGround;
	}
	
	public function courseOverGround()
	{
		return $this->_courseOverGround;
	}
	
		public function setWaterDepth($waterDepth)
	{
		$this->_waterDepth = $waterDepth;
	}
	
	public function waterDepth()
	{
		return $this->_waterDepth;
	}
	
		public function setWaterTemperature($waterTemperature)
	{
		$this->_waterTemperature = $waterTemperature;
	}
	
	public function waterTemperature()
	{
		return $this->_waterTemperature;
	}
	
		public function setGpsFix($gpsFix)
	{
		$this->_gpsFix = $gpsFix;
	}
	
	public function gpsFix()
	{
		return $this->_gpsFix;
	}
	
	public function isValid()
	{
		if($this->timestamp() == null)
			return false;
		if($this->latitude() == null)
			return false;
		if($this->longitude() == null)
			return false;
		return true;
	}
	
	public function toArray()
	{
		$speedThroughWater = ($this->speedThroughWater() != null) ? $this->speedThroughWater() : 0;
		$speedOverGround = ($this->speedOverGround() != null) ? $this->speedOverGround() : 0;
		$courseOverGround = ($this->courseOverGround() != null) ? $this->courseOverGround() : 0;
		$waterDepth = ($this->waterDepth() != null) ? $this->waterDepth() : 0;
		$waterTemperature = ($this->waterTemperature() != null) ? $this->waterTemperature() : 0;
		$gpsFix = ($this->gpsFix() != null) ? $this->gpsFix() : 0;
	
		return [
			"latitude" => $this->latitude(),
			"longitude" => $this->longitude(),
			"speedthroughwater" => $speedThroughWater,
			"speedoverground" => $speedOverGround,
			"courseoverground" => $courseOverGround,
			"waterdepth" => $waterDepth,
			"watertemperature" => $waterTemperature,
			"gpsfix" => $gpsFix,
		];
	}

	private $_time;
	private $_latitude, $_longitude;
	private $_speedThroughWater, $_speedOverGround, $_courseOverGround;
	private $_waterDepth, $_waterTemperature;
	private $_gpsFix;
}

?>
