#pragma once

#include "CoreMinimal.h"
#include "SkyPortalFigure.generated.h"

//Copyright (C) 2010 Activision.All Rights Reserved.
static const uint8 HASH_CONST[] = {
				0x20, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x43, 0x29, 0x20, 0x32, // Copyright (C) 2
				0x30, 0x31, 0x30, 0x20, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0x2E, 0x20, // 010 Activision.
				0x41, 0x6C, 0x6C, 0x20, 0x52, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x52, 0x65, 0x73, 0x65, 0x72, // All Rights Reser
				0x76, 0x65, 0x64, 0x2E, 0x20 };																	// ved.

#define FIGURE_TOTAL_BLOCKS 64
#define FIGURE_BLOCK_SIZE 16


UENUM(BlueprintType)
enum EVariantIDGeneration {
	UNKNOW = -1,
  SPYROS_ADVENTURE = 0,
  GIANTS = 1,
  SWAP_FORCE = 2,
  TRAP_TEAM = 3,
  SUPERCHARGERS = 4,
  IMAGINATORS = 5
  
};

/*
typedef struct {
	unsigned char blockdata[FIGURE_TOTAL_BLOCKS][FIGURE_BLOCK_SIZE]; bool error;
} FigureDataBlock;
*/

UCLASS(BlueprintType,Blueprintable)
class UFigureData : public UObject {
	GENERATED_BODY()

public:

	UFigureData();

	// Data Arrays
	uint8 data[64][16];
	uint8 decryptedData[64][16];

	UPROPERTY(BlueprintReadOnly)
	bool bDecrypted;

	UPROPERTY(BlueprintReadOnly)
	bool dataError;

	// Properties
#pragma region manufacturer
	uint32 NUID; // should under no circumstances be corrupted. 4-byte
	uint8 BCC; //Block Check Character. When this BCC does not match the NUID of the tag, the tag ceases to function. stored in block 0 at offset 0x4
	uint8 SAK = 0x81; //needs to be set to allow for the tag to be read correctly
	uint16 ATQA; //always set to 0x01 0x0F
	FString ProductionYear; //last 2 digits of the year that the tag was manufactured as Binary-coded decimal
#pragma endregion
#pragma region Toy code
	uint32 ToyCodeNumber1, ToyCodeNumber2;
	uint64 FullToyCodeNumber;
	FString ToyCode;
#pragma endregion
	int16 ID; //Skylander ID
	int16 VariantID; //Skylander Variant ID
	EVariantIDGeneration GenerationID;
#pragma region counters
	uint8 counter1;
	uint8 counter2;
#pragma endregion
	FString Nickname;



	// Methods
	UFUNCTION(BlueprintCallable,BlueprintPure, meta = (Category = "SkyPortal|Figure"))
	int32 GetFigureID();

	UFUNCTION(BlueprintCallable,BlueprintPure, meta = (Category = "SkyPortal|Figure"))
	int32 GetVariantID();

	UFUNCTION(BlueprintCallable, BlueprintPure, meta = (Category = "SkyPortal|Figure"))
	EVariantIDGeneration GetGeneration();

	void ReadData(uint8 index);
	void ClearData();
	uint8 GetByte(int block, int offset);
	void SetByte(int block, int offset, uint8 value);
	uint16 GetShort(int block, int offset);
	uint32 GetUInt(int block, int offset);

	UFUNCTION(BlueprintCallable)
	bool Dump(bool decrypted, FString filePath);
};


