#include "history.h"

#include <QDateTime>
#include <QList>
#include <QString>

const char *History::HeaderPayload = "Header";
const char *History::MessageListPayload = "MessageList";

class History::Message::Private : public QSharedData
{
public:
  Private() {}

  Private( const Private& other ) : QSharedData( other )
  {
    mSender = other.mSender;
    mText   = other.mText;

    mTimestamp = other.mTimestamp;
  }

public:
  QString mSender;
  QString mText;

  QDateTime mTimestamp;
};

History::Message::Message() : d( new Private )
{
}

History::Message::Message( const History::Message &other ) : d( other.d )
{
}

History::Message::~Message()
{
}

History::Message &History::Message::operator=( const History::Message &other )
{
  if ( this != &other )
    d = other.d;

  return *this;
}

void History::Message::setSender( const QString &contactId )
{
  d->mSender = contactId;
}

QString History::Message::sender() const
{
  return d->mSender;
}

void History::Message::setText( const QString &text )
{
  d->mText = text;
}

QString History::Message::text() const
{
  return d->mText;
}

void History::Message::setTimestamp( const QDateTime &timestamp )
{
  d->mTimestamp = timestamp;
}

QDateTime History::Message::timestamp() const
{
  return d->mTimestamp;
}

class History::Private : public QSharedData
{
public:
  Private() {}

  Private( const Private &other ) : QSharedData( other )
  {
    mLocal  = other.mLocal;
    mRemote = other.mRemote;

    mMessages = other.mMessages;
  }

public:
  QString mLocal;
  QString mRemote;

  QList<History::Message> mMessages;
};

History::History() : d( new Private )
{
}

History::History( const History &other ) : d( other.d )
{
}

History::~History()
{
}

History &History::operator=( const History &other )
{
  if ( this != &other )
    d = other.d;

  return *this;
}

void History::setLocalContactId( const QString &contactId )
{
  d->mLocal = contactId;
}

QString History::localContactId() const
{
  return d->mLocal;
}

void History::setRemoteContactId( const QString &contactId )
{
  d->mRemote = contactId;
}

QString History::remoteContactId() const
{
  return d->mRemote;
}

void History::addMessage( const History::Message &message )
{
  d->mMessages << message;
}

History::Message::List History::messages() const
{
  return d->mMessages;
}

QString History::mimeType()
{
  return QLatin1String( "application/x-vnd.kde.imhistory" );
}
