#pragma once

#include <vector>
#include <string>
#include <filesystem>

class TemplateNode;
class TemplateTextBody;

using Path = std::filesystem::path;

class TemplateFile
{
public:
    TemplateFile(const Path& path);

    ~TemplateFile();

    std::string dumpContent();

    std::string getName() const;

    TemplateNode* getContent() const;

    bool hasLoaded() const;

    void loadContent();

private:
    std::size_t checkForStatement(const std::string& lineSection);

    std::size_t checkForExpression(const std::string& lineSection);

    void onTextSpanFinished();

    void onFoundStatement(const std::string& statement_string);

    void onFoundExpression(const std::string& expression_string);

    void onFoundBlock(const std::vector<std::string> args);

    void onFoundEndBlock(const std::vector<std::string> args);

    void onFoundExtends(const std::vector<std::string> args);

    void processLine(const std::string& line);

    Path mPath;
    std::string mParentName;
    std::vector<std::string> mRawContent;
    bool mHasLoaded{false};

    std::unique_ptr<TemplateNode> mRootNode;
    TemplateNode* mWorkingNode{ nullptr };

    std::string mWorkingLineContent;
    std::unique_ptr<TemplateTextBody> mWorkingTextSpan;
};
