using Dev.Scripts.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class EnumData<T> where T : struct, Enum
{
    [SerializeField] public string EncodedData { get; set; }
    [SerializeField] public List<T> DecodedData { get; set; }


    public EnumData(string encodedData)
    {
        EncodedData = encodedData;
    }

    public void EncodeData<T>()
    {
        EncodedData = string.Empty;
        DecodedData.ForEach(data => { EncodedData += data; });
    }
    public List<T> DecodeData<T>() where T : struct, Enum
    {
        if (string.IsNullOrEmpty(EncodedData))
        {
            Debug.Log("EncodedData is null");
            return null;
        }

        List<T> decodedData = new List<T>(); 
        var charArray = EncodedData.ToCharArray();
        foreach (var encodedChar in charArray)
        {
            int charParsedToInt = int.Parse(encodedChar.ToString());
            decodedData.Add((T)Enum.ToObject(typeof(T), charParsedToInt));
        }
        return decodedData;
    }
}
