using System;
using System.Collections.Generic;
using UnityEngine;

namespace Darkmatter.Libs.PlayerPrefs
{
    public enum PlayerPrefType
    {
        String,
        Int,
        Float,
        Bool
    }

    [Serializable]
    public class PlayerPrefKeyEntry
    {
        public string Key;
        public PlayerPrefType Type;
        public string Description;
    }

    [CreateAssetMenu(
        fileName = "PlayerPrefsKeyRegistry",
        menuName = "Darkmatter/Libs/PlayerPrefs Key Registry")]
    public class PlayerPrefsKeyRegistry : ScriptableObject
    {
        [SerializeField] private List<PlayerPrefKeyEntry> _entries = new();

        public IReadOnlyList<PlayerPrefKeyEntry> Entries => _entries;

        public void AddKey(string key, PlayerPrefType type, string description = "")
        {
            if (_entries.Exists(e => e.Key == key)) return;
            _entries.Add(new PlayerPrefKeyEntry
            {
                Key = key,
                Type = type,
                Description = description
            });
        }

        public void RemoveKey(string key)
        {
            _entries.RemoveAll(e => e.Key == key);
        }
    }
}
