#include "PdfOutline.h"

#include "PdfXRefTable.h"

std::string PdfOutline::toString(PdfXRefTable* xRefTable)
{
    mDictionary.addStringItem("Type", "/Outline");
    auto content = getStringPrefix();
    content += mDictionary.toString();
    content += getStringSuffix();
    xRefTable->addRecord(content.size(), mGenerationNumber, mIsFree);
    return content;
}

unsigned PdfOutlineCollection::indexObjects(unsigned count)
{
    auto newCount = count + 1;
    mObjectNumber = newCount;
    for (const auto& outline : mOutlines)
    {
        newCount = outline->indexObjects(newCount);
    }
    return newCount;
}

std::string PdfOutlineCollection::toString(PdfXRefTable* xRefTable)
{
    updateDictionary();
    std::string content = getStringPrefix();
    content += mDictionary.toString();
    content += getStringSuffix();
    xRefTable->addRecord(content.size(), mGenerationNumber, mIsFree);
    return content;
}

void PdfOutlineCollection::updateDictionary()
{
    mDictionary.addStringItem("Type", "/Outlines");
    mDictionary.addStringItem("Count", std::to_string(mOutlines.size()));
}
