#pragma once

#include "CoreMinimal.h"
#include "SkyPortalDefinitions.generated.h"

// This file is not supposed to have a c++ counterpart. Use it as a library


UENUM(BlueprintType)
enum class EFigureStatus : uint8
{
	NOT_PRESENT = 0b00 UMETA(DisplayName = "Not Present"),
	PRESENT = 0b01 UMETA(DisplayName = "Present"),
	ADDED = 0b11 UMETA(DisplayName = "Added"),
	REMOVED = 0b10 UMETA(DisplayName = "Removed")
};


UENUM(BlueprintType)
enum EPortalSide {
	LEFT UMETA(DisplayName = "Left side"),
	RIGHT UMETA(DisplayName = "Right side"),
	BOTH UMETA(DisplayName = "Both left and right"),
	TRAP UMETA(DisplayName = "Trap")
};

UENUM(BlueprintType)
enum EPortalCommand {
	A UMETA(DisplayName = "Activate"),
	C UMETA(DisplayName = "Color"),
	J UMETA(DisplayName = "Advanced color"),
	L UMETA(DisplayName = "Trap color"),
	M UMETA(DisplayName = "Music"),
	Q UMETA(DisplayName = "Query"),
	R UMETA(DisplayName = "Ready"),
	S UMETA(DisplayName = "Status")
};

USTRUCT(BlueprintType)
struct FPortalStatusData
{
	GENERATED_BODY()

	// Array of statuses
	UPROPERTY(BlueprintReadOnly, EditFixedSize, Category = "SkyPortal|Figure", meta = (EditFixedOrder))
	TArray<EFigureStatus> StatusArray;

	// timestamp.
	// only one byte long. This means that after the value 0xFF, it overflows back to 0x00.
	// Since these are so far apart, it can be assumed that 0x00 is newer than anything in the range 0xF0 - 0xFF.
	UPROPERTY(BlueprintReadOnly, Category = "SkyPortal|Figure")
	uint8 Counter;

	// Should always be true
	UPROPERTY(BlueprintReadOnly, Category = "SkyPortal|Figure")
	bool bIsReady;

	explicit FPortalStatusData(uint8 ArraySize = 16, EFigureStatus DefaultStatus = EFigureStatus::NOT_PRESENT) :
		Counter(0),
		bIsReady(true)
	{
		// Initialisation du tableau StatusArray avec 16 éléments par défaut
		StatusArray.Init(DefaultStatus, ArraySize);
	}

	// Overload the == operator
	// Different only between
	bool operator==(const FPortalStatusData& Other) const
	{
		if (bIsReady == Other.bIsReady && Counter == Other.Counter) {
			if (StatusArray == Other.StatusArray) {
				return true;
			}
		}
		return false;
	}

	// Overload the != operator
	bool operator!=(const FPortalStatusData& Other) const
	{
		return !(*this == Other);
	}
};
