// Copyright (c) 2026 GregOrigin. All Rights Reserved.
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Damageable.h"
#include "URPGInventoryComponent.h"
#include "ARPGCharacter.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnHealthChanged, float, NewHealth, float, MaxHealth);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnLevelUp, int32, NewLevel);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnDeath);

UCLASS()
class CODEFORGE_API ARPGCharacter : public ACharacter, public IDamageable
{
	GENERATED_BODY()

public:
	ARPGCharacter();

	UPROPERTY(ReplicatedUsing = OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "RPG")
	float Health;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
	float MaxHealth;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
	float AttackPower;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
	int32 Level;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
	int32 Experience;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "RPG")
	URPGInventoryComponent* InventoryComponent;

	UPROPERTY(BlueprintAssignable, Category = "RPG")
	FOnHealthChanged OnHealthChanged;

	UPROPERTY(BlueprintAssignable, Category = "RPG")
	FOnLevelUp OnLevelUp;

	UPROPERTY(BlueprintAssignable, Category = "RPG")
	FOnDeath OnDeath;

	UFUNCTION()
	void OnRep_Health();

	UFUNCTION(BlueprintCallable, Category = "RPG")
	void GainExperience(int32 Amount);

	UFUNCTION(BlueprintPure, Category = "RPG")
	float GetHealthPercent() const;

	UFUNCTION(BlueprintPure, Category = "RPG")
	bool IsAlive() const;

	// IDamageable implementation
	virtual void ReceiveDamage_Implementation(float Amount) override;
	virtual float GetCurrentHealth_Implementation() const override;
	virtual bool GetIsAlive_Implementation() const override;

	// Console Commands
	UFUNCTION(Exec)
	void CheatAttack();

	UFUNCTION(Exec)
	void CheatGainXP(int32 Amount);

	UFUNCTION(Exec)
	void CheatAddItem();

	UFUNCTION(Exec)
	void CheatHeal();

	UFUNCTION(Exec)
	void CheatNuke();

	UFUNCTION(Exec)
	void CheatGodMode();

	UFUNCTION(Server, Reliable)
	void ServerRequestAttack();

	UFUNCTION(Client, Reliable)
	void ClientReceiveDamage(float Amount);

	UFUNCTION(NetMulticast, Unreliable)
	void NetMulticastPlayHitEffect();

	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
};