#pragma once
#include "CoreMinimal.h"
#include "Subsystems/WorldSubsystem.h"
#include "LevelSequencePlayer.h"
#include "Engine/ObjectLibrary.h"
#include "PortaSequenceSubsystem.generated.h"

class AAvalancheActor;
class UAvalanchePlayback;

UCLASS()
class PORTAINTERFACE_API UPortaSequenceSubsystem : public UWorldSubsystem, public FTickableGameObject
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void StopAllSequencesStatic();

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void StopAllSequences();

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void PlaySequencesStatic(const TArray<FString>& Sequences);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void PlaySequences(const TArray<FString>& Sequences);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	bool PlaySequenceImmediate(const FString& Sequence);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	bool PlaySequenceReverse(const FString& Sequence);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static bool PlaySequenceReverseStatic(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void PauseSequence(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void PauseSequenceStatic(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void ResumeSequence(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void ResumeSequenceStatic(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void ResumeSequenceReverse(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void ResumeSequenceReverseStatic(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void SeekSequence(const FString& SequencePath, float Time);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	void ShowEndOfSequence(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void ShowEndOfSequenceStatic(const FString& SequencePath);

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void SeekSequenceStatic(const FString& SequencePath, float Time);
	
	UFUNCTION(BlueprintCallable, Category = "Porta")
	void ResetAllSequences();

	UFUNCTION(BlueprintCallable, Category = "Porta")
	static void ResetAllSequencesStatic();

	virtual void Tick(float DeltaTime) override;
	virtual TStatId GetStatId() const { return TStatId(); }


private:
	UPROPERTY(Transient)
	TMap<FString, ULevelSequencePlayer*> SequencePlayers;

	UPROPERTY(Transient)
	TArray<FString> PendingStarts;
};
