// Copyright 2024, CodeSpartan

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "HttpRequestCpp.h"
#include "HttpBlueprintTypes.h"
#include "HttpManagerCpp.generated.h"

UCLASS(Abstract, Blueprintable)
class MMOKITCODE_API AHttpManagerCpp : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AHttpManagerCpp();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	/* Body for GET requests is ignored, see documentation! */
	UFUNCTION(BlueprintCallable, Category = "HTTP Request", meta = (AutoCreateRefTerm = "BodyJson"))
	void CreateJsonRequest(const FJsonObjectWrapper& BodyJson, EHttpVerbs Verb, const FString& Path, const FOnHttpRequestResponse& OnResponse);

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "HTTP Request")
	TSubclassOf<UHttpRequestCpp> RequestClass;

	UFUNCTION(BlueprintImplementableEvent, Category = "HTTP Request")
	void TreatRequest(const FJsonObjectWrapper& BodyJson, EHttpVerbs Verb, const FString& Path, UHttpRequestCpp* CreatedRequest);	

};
