// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "WaypointActor.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "GameFramework/Actor.h"
#include <EndlessVendetta/EndlessVendettaGameMode.h>
#include "CheckpointClass.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedCheckpoint);

UCLASS()
class ENDLESSVENDETTA_API ACheckpointClass : public AActor
{
	GENERATED_BODY()

	FString BountyTitle;

	// ------ Properties set from Editor ------
	UPROPERTY(EditDefaultsOnly, Category = "Checkpoint")
	FString CheckpointTip;
	UPROPERTY(EditDefaultsOnly, Category = "Checkpoint")
	FVector WaypointLoc;
	UPROPERTY(EditDefaultsOnly, Category = "Checkpoint")
	UTexture2D* WaypointIcon;
	UPROPERTY(EditDefaultsOnly, Category = "Checkpoint")
	FTransform CheckpointSpawnTransform;
	UPROPERTY(EditDefaultsOnly, Category = "Checkpoint")
	TSubclassOf<AWaypointActor> WaypointActorClass;

	AWaypointActor* WaypointActor;
	// ----------------------------------------
protected:
	UFUNCTION(BlueprintCallable, Category = "Checkpoint")
	void BroadcastCompletion()
	{
		CompletedCheckpoint.Broadcast();
		Cast<AEndlessVendettaGameMode>(GetWorld()->GetAuthGameMode())->SendEvent("Check", CheckpointTip);
	}

	UFUNCTION(BlueprintCallable)
	void UpdateChecpointWaypoint(FVector WaypointNewLoc);
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	virtual void Destroyed() override;

public:
	FCompletedCheckpoint CompletedCheckpoint;

	UPROPERTY(BlueprintReadOnly, Category = "Checkpoint")
	bool Active = false;

	void SpawnWaypoint(const FString& BountyTitle);

	UFUNCTION(BlueprintImplementableEvent)
	void CheckpointActivated();

	// ------ Getters for CP Properties ------

	FString GetCheckpointTip()
	{
		return CheckpointTip;
	}

	FVector GetWaypointLoc()
	{
		return WaypointLoc;
	}

	UTexture2D* GetWaypointIcon()
	{
		return WaypointIcon;
	}

	FTransform GetCheckpointSpawnTransform()
	{
		return CheckpointSpawnTransform;
	}

	// ---------------------------------------

	// Sets default values for this actor's properties
	ACheckpointClass();

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