#include "Contact.h"

CContact::CContact(QString ContactNbr, QString ContactName, QPixmap *Picture)
{

    mRAWContactNbr = ContactNbr;
    mContactNumber = ContactNbr;
    mContactNumber.insert(0,'(');
    mContactNumber.insert(4,") ");
    mContactNumber.insert(9,'-');

    mContactName = ContactName;
    if(mContactName == "")
    {
        mContactName = mContactNumber;
    }


    if(Picture == 0)
    {
        mContactPicture = QPixmap("./Ico/contact.png");
    }
    else
    {
        if(Picture->isNull())
        {
            mContactPicture = QPixmap("./Ico/contact.png");
        }
        else
        {
            mContactPicture = QPixmap(*Picture);
        }
    }



}

CContact::CContact()
{
    mContactNumber="INVALID";
    mContactPicture = QPixmap("./Ico/contact.png");
}

CContact::~CContact()
{

}

int CContact::SetContactImage(QString FilePath)
{
    mContactPicture = QPixmap(FilePath);

    return RET_OK;
}

bool operator ==(const CContact& left, const CContact& right)
{
    if(left.mRAWContactNbr == right.mRAWContactNbr)
    {
        return true;
    }

    return false;
}
bool operator !=(const CContact& left, const CContact& right)
{
    return !(left==right);
}

CContact & CContact::operator=(const CContact source)
{
    if(&source == this)
    {
        return *this;
    }

    this->mRAWContactNbr = source.mRAWContactNbr;
    this->mContactName = source.mContactName;
    this->mContactNumber = source.mContactNumber;
    this->mContactPicture = source.mContactPicture;

    return *this;
}

QDataStream &operator<<(QDataStream &out, const CContact &source)
{
    out << source.mContactName
        << source.mContactNumber
        << source.mContactPicture
        << source.mRAWContactNbr;


    return out;
}

QDataStream &operator>>(QDataStream &in, CContact &dest)
{
    in >> dest.mContactName
       >> dest.mContactNumber
       >> dest.mContactPicture
       >> dest.mRAWContactNbr;



    return in;
}
