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

namespace Intrepid.Gameplay.Codex.Knowledge
{
    [Serializable]
    [GroupConfigurations("Codex Ontology"), HideLabel]
    public class CodexOntology
    {
        [SerializeField] private List<CodexConceptTag> knownConcepts = new();

        public IReadOnlyList<CodexConceptTag> KnownConcepts => knownConcepts.Where(c => c.IsNotNull()).Distinct().ToList();

        public bool Knows(CodexConceptTag concept)
        {
            return concept.IsNotNull() && knownConcepts.Contains(concept);
        }

        public bool Learn(CodexConceptTag concept)
        {
            if (concept.IsNull()) return false;
            if (knownConcepts.Contains(concept)) return false;
            knownConcepts.Add(concept);
            return true;
        }

        public bool Forget(CodexConceptTag concept)
        {
            if (concept.IsNull()) return false;
            return knownConcepts.Remove(concept);
        }

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