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

#define DBITEM__H

#include <qglobal.h>

#include <QStringList>
#include <QVariantList>
#include <QVariant>

class DbItem
{
	public:
		DbItem(const QString& table_name, const QStringList& cols);
		DbItem(quint64 id, const QString& table_name, const QStringList& cols);
		virtual ~DbItem() {}

	public:
		virtual QVariant id() const { return m_Id.toULongLong() > 0 ?  m_Id : QVariant(); }

		virtual bool serialize() = 0;
		virtual bool remove();

		virtual void setDirty(bool b) { m_Dirty = b; }
		virtual bool isDirty() { return m_Dirty; }

		virtual bool isRemoved() const { return m_Removed; }
		virtual void setRemoved(bool b = true) { m_Removed = b; }

		virtual bool isNew() const { return m_New; }
		virtual void setNew(bool b = true) { m_New = b; }

		const QString& tableName() const { return m_TableName; }
		const QStringList& columnNames() const { return m_ColumnNames; }

	protected:
		bool serialize(QVariantList values);

	private:
		QVariant m_Id;
		bool m_Dirty;
		bool m_Removed;
		bool m_New;
		QString m_TableName;
		QStringList m_ColumnNames;
};

#endif
