#pragma once

#include "CoreMinimal.h"
#include "SurvivorStatusInterface.h"
#include "KillerPowerReference.h"
#include "CharacterDreamworldComponent.h"
#include "Templates/SubclassOf.h"
#include "SurvivorSleepiness.h"
#include "TunableStat.h"
#include "GameplayTagContainer.h"
#include "FastTimer.h"
#include "EHealthState.h"
#include "SurvivorDreamworldComponent.generated.h"

class AKiller;
class UStatusEffect;
class UTimerObject;
class ADBDPlayer;

UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
class USurvivorDreamworldComponent : public UCharacterDreamworldComponent, public ISurvivorStatusInterface, public IKillerPowerReference
{
	GENERATED_BODY()

private:
	UPROPERTY(BlueprintReadWrite, Replicated, Transient, meta=(AllowPrivateAccess=true))
	AKiller* _linkedKiller;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	TSubclassOf<UStatusEffect> _survivorDreamWorldStatusEffect;

	UPROPERTY(BlueprintReadWrite, Replicated, Transient, meta=(AllowPrivateAccess=true))
	FSurvivorSleepiness _survivorSleepiness;

	UPROPERTY(BlueprintReadWrite, Replicated, Transient, Instanced, meta=(AllowPrivateAccess=true))
	UTimerObject* _sleepinessProtectionTimer;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	FTunableStat _sleepGainPerSecondStat;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	FTunableStat _clockSleepinessProtectionStat;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	FTunableStat _sleepThresholdStat;

	UPROPERTY(EditAnywhere)
	FGameplayTagQuery _inHealActionInDreamworldQuery;

	UPROPERTY(BlueprintReadWrite, Replicated, Transient, meta=(AllowPrivateAccess=true))
	bool _isImmuneFromSleepiness;

	UPROPERTY(BlueprintReadWrite, ReplicatedUsing=OnRep_ShowKiller, Transient, meta=(AllowPrivateAccess=true))
	bool _showKiller;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	FFastTimer _killerGlimpseDurationTimer;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	FFastTimer _killerGlimpseCooldownTimer;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	float _glimpseMinDistance;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	float _glimpseMaxDistance;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	float _killerGlimpseCooldown;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	float _killerGlimpseDuration;

	UPROPERTY(BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	bool _useScriptedKillerVisibility;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, meta=(AllowPrivateAccess=true))
	bool _showKillerInstantly;

public:
	UFUNCTION(BlueprintCallable)
	void SetScriptedKillerVisibility(bool useScriptedKillerVisibility);

private:
	UFUNCTION(BlueprintCallable)
	void OnRep_ShowKiller();

public:
	UFUNCTION(BlueprintCallable)
	void Local_SetShowKiller(bool showKiller, bool instantly);

private:
	UFUNCTION(BlueprintCallable)
	void InitializeTunableValues(AKiller* killer);

protected:
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
	void HandleShowKillerChanged(bool showKiller, bool instantly);

public:
	UFUNCTION(BlueprintPure)
	AKiller* GetLinkedKiller() const;

	UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
	void Authority_WakeUpByWakerObject();

	UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
	void Authority_WakeUpByOther(ADBDPlayer* instigator);

	UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
	void Authority_WakeUpByHookOrDying();

	UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
	void Authority_PutAsleep();

private:
	UFUNCTION(BlueprintCallable)
	void Authority_OnHealthStateChanged(EHealthState oldHealthState, EHealthState newHealthState);

	UFUNCTION(BlueprintCallable)
	void Authority_OnAttacked();

public:
	UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly)
	void Authority_HandleSkillCheckFailure(bool wakeUpEveryoneInteracting, ADBDPlayer* instigator);

public:
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

public:
	USurvivorDreamworldComponent();
};

FORCEINLINE uint32 GetTypeHash(const USurvivorDreamworldComponent) { return 0; }
