#pragma once

#include "CoreMinimal.h"
#include "WingBasics.h"
#include "WingManual.h"
#include "WingServer.h"
#include "Documentation_Section.generated.h"

UCLASS()
class UWing_Documentation_Section : public UWingHandler
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, meta=(Description="Manual section"))
	FString Section;

	virtual void Register() override
	{
		TStringBuilder<128> Docs;
		Docs.Append(TEXT("Print a section of the manual. Valid sections: "));
		WingManual::PrintSectionNames(nullptr, WingManual::GetSections(), Docs);
		UWingServer::AddHandler(this, Docs.ToString());
	}
	virtual void Handle() override
	{
		FName SectionName(*Section);
		if (WingManual::PrintSection(SectionName))
		{
			WingOut::Stdout.Printf(TEXT("\n"));
			WingManual::PrintSectionNames(TEXT("Other manual sections:"), WingManual::GetSections(), WingOut::Stdout);
		}
		else
		{
			WingOut::Stdout.Printf(TEXT("Unknown manual section '%s'\n"), *Section);
			WingManual::PrintSectionNames(TEXT("Valid manual sections:"), WingManual::GetSections(), WingOut::Stdout);
		}
	}
};
