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

#pragma once

#include "CoreMinimal.h"
#include "SUDSParticipant.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/Pawn.h"
#include "Faye/Components/NpcPawnMovement.h"
#include "NpcPawn.generated.h"

class UOrderSettingsDataAsset;
class UCoffeeFilter;
class UStatForgeComponent;
class UStateTree;
class UBookFilter;
class AShelfActor;
class UStateTreeComponent;

USTRUCT(BlueprintType)
struct FNpcBaseData
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "NPC")
	FName NpcName;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "NPC")
	FText NpcDisplayName;
};

UCLASS()
class FAYE_API ANpcPawn : public APawn, public ISUDSParticipant
{
	GENERATED_BODY()

public:
	ANpcPawn();
	virtual void Tick(float DeltaTime) override;
	virtual UPawnMovementComponent* GetMovementComponent() const override;
	
	UFUNCTION(BlueprintPure, Category = "NPC")
	FName GetNpcName() const { return NpcBaseData.NpcName; }
	
	UFUNCTION(BlueprintPure, Category = "NPC")
	FNpcBaseData GetNpcBaseData() const { return NpcBaseData; }
	
	//DIALOGUE
	virtual void OnDialogueStarting_Implementation(USUDSDialogue* Dialogue, FName AtLabel) override;
	
	UFUNCTION(BlueprintPure, Category = "NPC")
	UStateTreeComponent* GetStateTreeComponent() const { return StateTreeComponent; }

	UFUNCTION(BlueprintCallable, Category = "NPC")
	void GenerateBookFilter();
	UFUNCTION(BlueprintPure, Category = "NPC")
	UBookFilter* GetChosenBookFilter() const { return ChosenBookFilter; }
	
	UFUNCTION(BlueprintCallable)
	void GenerateCoffeeFilter();
	UFUNCTION(BlueprintPure, Category = "NPC")
	UCoffeeFilter* GetChosenCoffeeFilter() const { return ChosenCoffeeFilter; }
	
	TObjectPtr<UOrderSettingsDataAsset> GetCustomOrderSettings() const { return CustomOrderSettings; }
	
protected:
	virtual void BeginPlay() override;
	
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	FNpcBaseData NpcBaseData;
	
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	TSoftObjectPtr<UStateTree> StateTree;
	
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	TObjectPtr<UOrderSettingsDataAsset> CustomOrderSettings;
	
	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UCapsuleComponent> CapsuleComponent;

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UNpcPawnMovement> MovementComponent;
	
	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UStateTreeComponent> StateTreeComponent;
	
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
	TObjectPtr<UStatForgeComponent> StatForgeComponent;
	
	UPROPERTY()
	TObjectPtr<UBookFilter> ChosenBookFilter = nullptr;
	
	UPROPERTY()
	TObjectPtr<UCoffeeFilter> ChosenCoffeeFilter = nullptr;
};
