// Oleg Petruny proprietary.

#pragma once

#include "UObject/Object.h"

#include "CutsceneManager.generated.h"

DECLARE_DYNAMIC_DELEGATE(FCutsceneEndCallback);

UCLASS(BlueprintType)
class UCutsceneManager : public UObject
{
    GENERATED_BODY()

public:
    UCutsceneManager();

    UFUNCTION(BlueprintCallable)
    void EnqueueSequence(class ULevelSequence* sequence, FCutsceneEndCallback endCallback);

    UFUNCTION(BlueprintCallable)
    void SkipSequence();

    UFUNCTION(BlueprintCallable)
    void ClearQueue();

    UFUNCTION(BlueprintCallable)
    void LockCallback(bool lock);

private:
    void PlayNextSequence();
    UFUNCTION()
    void OnSequenceEnd();

    void OnInputHold();
    void OnInputUnhold();

    class ULevelSequencePlayer* _sequencePlayer = nullptr;
    class ALevelSequenceActor* _sequencePlayerActor = nullptr;
    TQueue<class ULevelSequence*> _nextSequences;
    FCriticalSection _sequencesLock;
    TQueue<FCutsceneEndCallback> _endCallbacks;
    FCriticalSection _callbacksLock;

    class APlayerBase* _lastPlayer = nullptr;
    TSoftObjectPtr<class UInputMappingContext> _inputContext;
    TPair<int32, int32> _handlers;

    bool _lockCallback = false;
    bool _lastlySkipped = false;
    bool _holding = false;
};
