#pragma once

#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "AbstractPainter.h"
#include "Scene.h"

#include "SvgPainter.h"
#include "SvgWriter.h"
#include "SvgDocument.h"

#include "Image.h"
#include "PngWriter.h"

#include "FontsManager.h"

#include "File.h"

class TestRenderer
{
public:
	TestRenderer(unsigned width = 1000, unsigned height = 1000)
	{
		mFontsManager = std::make_unique<FontsManager>();

		mSurface = std::make_unique<DrawingSurface>();
		mSurface->setSize(width, height);

		mDrawingContext = std::make_unique<DrawingContext>(mSurface.get());

		getScene()->setFontsManager(mFontsManager.get());
	}

	Scene* getScene() const
	{
		return mSurface->getScene();
	}

	void write(const Path& path)
	{
		mDrawingContext->paint();

		auto image = mSurface->getImage();

		PngWriter writer;
		writer.write(path, image);
	}

	void writeSvg(const Path& path)
	{
		writeSvg(path, mSurface->getScene());
	}

	static void writeSvg(const Path& path, Scene* scene)
	{
		SvgPainter painter;
		auto svg_document = painter.paint(scene);

		SvgWriter writer;
		auto svg_content = writer.toString(svg_document.get());

		File svg_file(path);
		svg_file.writeText(svg_content);
	}

private:
	std::unique_ptr<DrawingSurface> mSurface;
	std::unique_ptr<DrawingContext> mDrawingContext;

	std::unique_ptr<FontsManager> mFontsManager;
};