// Copyright Pacificao. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "AgrarianInteractable.h"
#include "AgrarianCampfire.generated.h"

class UPointLightComponent;
class UStaticMeshComponent;

UCLASS(Blueprintable)
class AAgrarianCampfire : public AActor, public IAgrarianInteractable
{
	GENERATED_BODY()

public:
	AAgrarianCampfire();

	virtual void Tick(float DeltaSeconds) override;
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Fire")
	TObjectPtr<UStaticMeshComponent> Mesh;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Fire")
	TObjectPtr<UPointLightComponent> FireLight;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, ReplicatedUsing = OnRep_FireState, Category = "Agrarian|Fire")
	bool bLit = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Agrarian|Fire", meta = (ClampMin = "0"))
	float FuelSeconds = 0.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire", meta = (ClampMin = "0"))
	float WarmthRadius = 550.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire", meta = (ClampMin = "0"))
	float WarmthPerSecond = 0.02f;

	virtual FText GetInteractionText_Implementation(const AAgrarianGameCharacter* Interactor) const override;
	virtual bool CanInteract_Implementation(const AAgrarianGameCharacter* Interactor) const override;
	virtual void Interact_Implementation(AAgrarianGameCharacter* Interactor) override;

	UFUNCTION(BlueprintCallable, Category = "Agrarian|Fire")
	void AddFuel(float Seconds);

protected:
	UFUNCTION()
	void OnRep_FireState();

	void UpdateVisualState();
	void WarmNearbyCharacters(float DeltaSeconds);
};
