/***************************************************************************
 *   Copyright (C) 2010 by Volker Lanz <vl@fidra.de>                       *
 *                                                                         *
 *   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 2 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

#if !defined(TRACK__H)

#define TRACK__H

#include "core/types.h"
#include "core/dbitem.h"

#include <QList>

class QSqlQuery;
class TrackPoint;
class Lap;

class Track : public DbItem
{
	Q_DISABLE_COPY(Track);

	friend class Lap;

	public:
		Track(Lap* lap, const QSqlQuery& query);
		Track();
		~Track();

	public:
		bool serialize();
		static bool list(Lap* lap, Tracks& result);

		quint32 calcTotalAscent() const;
		quint32 calcTotalDescent() const;
		quint32 calcMaxSpeed() const;
		quint32 calcAverageCadence() const;
		bool calcHeartRates(quint32& avg, quint32& max) const;
		quint32 calcDistance() const;
		quint32 calcDuration() const;
		QDateTime calcStartTime() const;
		bool calcBoundaries(double& minLat, double& minLon, double& maxLat, double& maxLon) const;

		void addTrackPoint(TrackPoint* tp);
		const TrackPoints& trackPoints() const;
		void calcTrackPointSpeed();

	protected:
		const Lap* lap() const { return m_Lap; }
		void setLap(Lap* lap) { m_Lap = lap; setDirty(true); }

		void clear();

	private:
		Lap* m_Lap;
		mutable bool m_TrackPointsLoaded;
		mutable TrackPoints m_TrackPoints;
};

#endif
