#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()));
}
