/***************************************************************************
 *   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(EQUIPMENT__H)

#define EQUIPMENT__H

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

#include <QString>
#include <QDate>
#include <QPixmap>
#include <qglobal.h>
#include <QMap>

class Activity;
class Profile;

class QSqlQuery;
class QComboBox;

class Equipment : public DbItem
{
	friend class Activity;
	friend class Profile;

	public:
		Equipment(Profile* p, const QSqlQuery& query);
		explicit Equipment(Profile* p = NULL, const QString& name = QString());

	public:
		virtual bool serialize();
		static bool list(Profile* p, Equipments& result);

		const QString& name() const { return m_Name; }
		const QString& model() const { return m_Model; }
		const QString& brand() const { return m_Brand; }
		const QDate& purchaseDate() const { return m_PurchaseDate; }
		const QString& type() const { return m_Type; }
		quint32 weight() const { return m_Weight; }
		bool isInUse() const { return m_InUse; }
		const QString& notes() const { return m_Notes; }
		QPixmap& photo() { return m_Photo; }
		const QPixmap& photo() const { return m_Photo; }

		void setName(const QString& s) { m_Name = s; setDirty(true); }
		void setModel(const QString& s) { m_Model = s; setDirty(true); }
		void setBrand(const QString& s) { m_Brand = s; setDirty(true); }
		void setPurchaseDate(const QDate& d) { m_PurchaseDate = d; setDirty(true); }
		void setType(const QString& s) { m_Type = s; setDirty(true); }
		void setWeight(quint32 w) { m_Weight = w; setDirty(true); }
		void setInUse(bool b) { m_InUse = b; setDirty(true); }
		void setNotes(const QString& s) { m_Notes = s; setDirty(true); }
		void setPhoto(const QPixmap& p) { m_Photo = p; setDirty(true); }

		static void toComboBox(QComboBox* combo, const Equipments& eqs);

	protected:
		Profile* profile() { return m_Profile; }
		void setProfile(Profile* p) { m_Profile = p; setDirty(true); }

	private:
		Profile* m_Profile;
		QString m_Name;
		QString m_Model;
		QString m_Brand;
		QDate m_PurchaseDate;
		QString m_Type;
		quint32 m_Weight; ///< in gram
		bool m_InUse;
		QString m_Notes;
		QPixmap m_Photo;
};

Q_DECLARE_METATYPE(Equipment*);

#endif
