// Copyright 2024, CodeSpartan

#include "HttpManagerCpp.h"
#include "HttpRequestCpp.h"

// Sets default values
AHttpManagerCpp::AHttpManagerCpp()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AHttpManagerCpp::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AHttpManagerCpp::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void AHttpManagerCpp::CreateJsonRequest(const FJsonObjectWrapper& BodyJson, EHttpVerbs Verb, const FString& Path, const FOnHttpRequestResponse& OnResponse)
{
	if (RequestClass == nullptr) 
	{
		UE_LOG(LogTemp, Warning, TEXT("Log: RequestClass default value isn't set in BP_HttpManager blueprint. Set RequestClass to BP_HttpRequest"));
		return;
	}
	UHttpRequestCpp* RequestObject = NewObject<UHttpRequestCpp>(this, RequestClass);
	RequestObject->OnResponseDelegate = OnResponse;
	TreatRequest(BodyJson, Verb, Path, RequestObject);
}