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

namespace Intrepid.Gameplay.Entities.Player.ActionBelt
{
    public abstract class ActionCallable : Identification
    {
        [GroupConfigurations, SerializeField, EnumPaging] private ActionCategory actionCategory = ActionCategory.General;
        [GroupConfigurations, SerializeField, ToggleLeft, PropertySpace] private bool canBeDropped;
        [ShowIf("IsNotTerminal")]
        [GroupConfigurations, SerializeField, ToggleLeft, PropertySpace] private bool shouldDropFromBeltWhenActivated;

        private bool IsNotTerminal => actionCategory != ActionCategory.Terminal;
        
        private ActionCategory ActionCategory => actionCategory;
        private bool CanBeDropped => canBeDropped;
        private bool ShouldDropFromBeltWhenActivated => shouldDropFromBeltWhenActivated;
        protected virtual LocalizationTag ActionLocalization { get; }
        protected virtual LocalizationTag DescriptionLocalization { get; }
        protected virtual List<string> Parameters { get; } = new();

        public bool IsEnabled { get; protected set; } = true;
        public bool IsNotEnabled => !IsEnabled;
        
        protected abstract void Execute(ActionIdentifier identifier);

        public virtual ActionEnvelope BuildEnvelope()
        {
            return new ActionEnvelope
            {
                ActionIdentifier = new ActionIdentifier
                {
                    Id = Id,
                },
                CanBeDropped = CanBeDropped,
                ActionCategory = ActionCategory,
                ActionLocalization = ActionLocalization,
                DescriptionLocalization = DescriptionLocalization,
                DescriptionParams = Functions.GetParams(Parameters),
                Callback = ai =>
                {
                    Execute(ai);
                    return ActionCategory.Terminal.Equals(ActionCategory) || ShouldDropFromBeltWhenActivated;
                }
            };
        }
    }
}