#include "PdfObject.h"

#include "PdfDictionary.h"
#include "PdfXRefTable.h"

std::string PdfObject::toString(PdfXRefTable* xRefTable)
{
    updateDictionary();

    auto content = getStringPrefix();
    content += mDictionary.toString();
    content += getStringSuffix();

    xRefTable->addRecord(content.size(), mGenerationNumber, mIsFree);
    return content;
}

void PdfObject::updateDictionary()
{

}

std::string PdfObject::getStringSuffix() const
{
    return "endobj\n\n";
}

unsigned PdfObject::indexObjects(unsigned count)
{
    const auto newCount = count + 1;
    mObjectNumber = newCount;
    return newCount;
}

void PdfObject::setObjectNumber(unsigned num)
{
    mObjectNumber = num;
}

void PdfObject::setGenerationNumber(unsigned num)
{
    mGenerationNumber = num;
}

std::string PdfObject::getStringPrefix() const
{
    return std::to_string(mObjectNumber) + " " + std::to_string(mGenerationNumber) + " obj\n";
}

std::string PdfObject::getRefString() const
{
    return std::to_string(mObjectNumber) + " " + std::to_string(mGenerationNumber) + " R";
}

bool PdfObject::isFree() const
{
    return mIsFree;
}
