#pragma once

#include "MarkdownContentParser.h"
#include "File.h"

#include <string>
#include <iostream>
#include <unordered_map>

class ContentFile
{
public:
    using FileMetadata = std::unordered_map<std::string, std::string>;
    using FileContentBody = std::vector<std::string>;

    ContentFile(const Path& filename)
        : mFilename(filename)
    {

    }

    virtual ~ContentFile() = default;

    Path getFilename() const
    {
        return mFilename;
    }

    virtual void load()
    {
        MarkdownContentParser parser;
        parser.run(mFilename);

        mMetadata = parser.getFileMetadata();
        mContentBody = parser.getContentBody();
    }

    std::string getMetadataItem(const std::string& key) const
    {
        const auto check = mMetadata.find(key);
        if (check == mMetadata.end())
        {
            return {};
        }
        else
        {
            return check->second;
        }
    }

protected:
    Path mFilename;
    FileMetadata mMetadata;
    FileContentBody mContentBody;
};

class ContentPage : public ContentFile
{
public:

    ContentPage(const Path& filename)
        : ContentFile(filename)
    {

    }

    void load() override
    {
        ContentFile::load();
    }

    std::string getOutputLocation() const
    {
        const auto metadata_item = getMetadataItem("save_as");
        return metadata_item.empty() ? File::getBaseFilename(mFilename) : metadata_item;
    }
};

class ContentArticle : public ContentFile
{
public:

    ContentArticle(const Path& filename)
        : ContentFile(filename)
    {

    }

    void load() override
    {
        ContentFile::load();
    }
};
