#pragma once

#include "CoreMinimal.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "HyperTwistDrillManager.generated.h"

// Forward declarations
struct FDrillCase;
class UHyperTwistDrillAsset;

UENUM(BlueprintType)
enum class EDrillState : uint8
{
    Idle,
    Presenting, // Showing the initial state
    AwaitingInput, // Waiting for user to recognize/solve
    ShowingSolution
};

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnDrillStateChanged, EDrillState, NewState);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnNewDrillCase, const FDrillCase&, NewCase);

UCLASS()
class HYPERTWISTTRAINING_API UHyperTwistDrillManager : public UGameInstanceSubsystem
{
    GENERATED_BODY()

public:
    //~ Begin USubsystem
    virtual void Initialize(FSubsystemCollectionBase& Collection) override;
    virtual void Deinitialize() override;
    //~ End USubsystem

    UFUNCTION(BlueprintCallable, Category = "Drill")
    void StartDrill(UHyperTwistDrillAsset* DrillAsset);

    UFUNCTION(BlueprintCallable, Category = "Drill")
    void Next();

    UFUNCTION(BlueprintCallable, Category = "Drill")
    void ShowSolution();

    UFUNCTION(BlueprintCallable, Category = "Drill")
    void AddCurrentCaseToFavorites();

    UPROPERTY(BlueprintAssignable, Category = "Drill")
    FOnDrillStateChanged OnDrillStateChanged;

    UPROPERTY(BlueprintAssignable, Category = "Drill")
    FOnNewDrillCase OnNewDrillCase;

private:
    void LoadUserData();
    void SaveUserData();

    void SetState(EDrillState NewState);

    UPROPERTY()
    TArray<FDrillCase> ActiveDrillQueue;

    UPROPERTY()
    int32 CurrentCaseIndex;

    UPROPERTY()
    EDrillState CurrentState;

    UPROPERTY()
    struct FDrillUserData UserData;
};
