// Oleg Petruny proprietary.

#pragma once

#include "GameFramework/Actor.h"

#include "Minigame.generated.h"

UENUM(BlueprintType)
enum class EMinigameResult : uint8
{
    Loss,
    Win,
};

DECLARE_DYNAMIC_DELEGATE_TwoParams(FMinigameEndCallback, EMinigameResult, result, int32, score);

/**
 * Interface for all minigame classes.
 * Any minigame is started/ended/restarted by executing Start()/End()/Restart() on specific instance.
 * Each call is after broadcasted into a blueprint event also.
 * On start the caller can pass a OnEndCallback delegate to receive result and score on a minigame end.
 * Each minigame can have its own contextInput
 */
UCLASS(Abstract, Blueprintable, BlueprintType, MinimalAPI)
class AMinigame : public AActor
{
    GENERATED_BODY()

public:
    AMinigame();

    UFUNCTION(BlueprintCallable)
    virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate);
    UFUNCTION(BlueprintImplementableEvent)
    void OnStart();

    UFUNCTION(BlueprintCallable)
    virtual void End();
    UFUNCTION(BlueprintImplementableEvent)
    void OnEnd();

    UFUNCTION(BlueprintCallable)
    virtual void Restart() {}
    UFUNCTION(BlueprintImplementableEvent)
    void OnRestart();

    UFUNCTION(BlueprintPure)
    TSoftObjectPtr<class UInputMappingContext> GetInputMappings() { return context; }

protected:
    FMinigameEndCallback callback;
    class APlayerBase* player;

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    int32 score = 0;

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    EMinigameResult result = EMinigameResult::Loss;

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    bool ended = false;

    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
    TSoftObjectPtr<class UInputMappingContext> context = nullptr;
};

