using System;
using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Wearable.Events;

namespace VOID.Generic.Objects.Armor
{
    [Serializable]
    public class ArmorObjectState : ObjectComponent<ArmorObject>
    {
        #region Initialize

        protected override void EventInitialize()
        {
            parent.wearableEvents.onEquippedAfter.AddListener(OnEquip);
            parent.wearableEvents.onUnEquippedAfter.AddListener(OnUnEquip);
        }

        #endregion

        private void OnEquip(EquipEvent equipEvent)
        {
            // Hide top and bottom underwear if needed
            if (parent.armorData.hideBottomUnderwear && equipEvent.unit.unitData.bottomUnderwear) 
                equipEvent.unit.unitData.bottomUnderwear.SetActive(false);
            if (parent.armorData.hideTopUnderwear && equipEvent.unit.unitData.topUnderwear) 
                equipEvent.unit.unitData.topUnderwear.SetActive(false);
        }

        private void OnUnEquip(UnEquipEvent unEquipEvent)
        {
            // Show top and bottom underwear if needed
            if (parent.armorData.hideBottomUnderwear && unEquipEvent.unit.unitData.bottomUnderwear) 
                unEquipEvent.unit.unitData.bottomUnderwear.SetActive(true);
            if (parent.armorData.hideTopUnderwear && unEquipEvent.unit.unitData.topUnderwear) 
                unEquipEvent.unit.unitData.topUnderwear.SetActive(true);
        }
    }
}