using System;
using System.Collections.Generic;
using System.Linq;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using UnityEngine;

namespace Intrepid.Gameplay.Codex.Visual
{
    [Serializable]
    [GroupConfigurations("Pictorial Protocol Inventory"), HideLabel]
    public class PictorialProtocolInventory
    {
        [SerializeField] private List<PictorialProtocolTag> knownProtocols = new();

        public IReadOnlyList<PictorialProtocolTag> KnownProtocols => knownProtocols.Where(p => p.IsNotNull()).Distinct().ToList();

        public bool Knows(PictorialProtocolTag protocol)
        {
            return protocol.IsNotNull() && knownProtocols.Contains(protocol);
        }

        public bool Unlock(PictorialProtocolTag protocol)
        {
            if (protocol.IsNull()) return false;
            if (knownProtocols.Contains(protocol)) return false;
            knownProtocols.Add(protocol);
            return true;
        }

        public bool Forget(PictorialProtocolTag protocol)
        {
            if (protocol.IsNull()) return false;
            return knownProtocols.Remove(protocol);
        }

#if UNITY_EDITOR
        [GroupDebug, Button(ButtonSizes.Medium)]
        private void CleanupKnownProtocols()
        {
            knownProtocols = knownProtocols.Where(p => p.IsNotNull()).Distinct().ToList();
        }
#endif
    }
}
