using Jovian.InspectorTools;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Nox.Game {
    public interface IModfiersFactory {
        IReadOnlyCollection<ModifierDefinition> GetAll();
        ModifierDefinition GetById(Guid modifierId);
        IReadOnlyCollection<ModifierDefinition> GetModifiersFor(CharacterDefinition character);
        bool TryAddModifier(CharacterDefinition character, string modiferId);
    }

    public enum ModifierOperation {
        None,
        Flat,
        Addition,
        Multiplication,
        Percentage
    }

    [Serializable]
    public sealed class ModifierDefinition {
        public string name;
        [ReadOnly]
        public Guid id = Guid.NewGuid();
        public StatType statType;
        public AttributeType attributeType;
        public ModifierOperation operation;
        public float value;
    }

    [Serializable]
    public sealed class ModifiersData {
        public ModifierDefinition[] modifiers;
    }

    public class ModifiersFactory : IModfiersFactory {
        private readonly ModifiersRegistry modifiersRegistry;
        private readonly Dictionary<Guid, ModifierDefinition> modifierPool = new ();

        public ModifiersFactory(ModifiersRegistry modifiersRegistry) {
            this.modifiersRegistry = modifiersRegistry;
            var allAvailableModifiers = modifiersRegistry.modifiersData;
            foreach(var modifier in allAvailableModifiers.modifiers) {
                modifierPool.Add(modifier.id, modifier);
            }
        }

        public IReadOnlyCollection<ModifierDefinition> GetAll() {
            return modifiersRegistry.modifiersData.modifiers;
        }
        public ModifierDefinition GetById(Guid modifierId) {
            return modifiersRegistry.modifiersData.modifiers.FirstOrDefault(m => m.id == modifierId);
        }
        public IReadOnlyCollection<ModifierDefinition> GetModifiersFor(CharacterDefinition character) {
            throw new NotImplementedException();
        }
        public bool TryAddModifier(CharacterDefinition character, string modiferId) {
            throw new NotImplementedException();
        }
    }
}
