using Framework.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.ItemSystem
{
    public class ExposeItemProperties : CoreAction
    {
        public ExposeItemProperties(CoreBehaviour sender)
            : base(sender)
        {
        }

        /// <summary>
        /// Gets the ItemProperties component.
        /// </summary>
        /// <returns></returns>
        public ItemProperties GetItemProperties()
        {
            return (ItemProperties)GetSender();
        }
    }

    /// <summary>
    /// A container for item information that should be populated by the Actor equipping the object.
    /// It should be populated with an <see cref="Item"/> object which contains persistent information
    /// about an item. It should also be populated with a holder/equipper which will generally be an
    /// instance of <see cref="Hands"/>, this component should then expose itself to other components
    /// on this Item gameObject.
    /// </summary>
    public class ItemProperties : CoreBehaviour
    {
        public string itemEditorDetails;
        private Itemlike item;
        private CoreBehaviour holder;

        public Itemlike GetItem()
        {
            return this.item;
        }

        public CoreBehaviour GetHolder()
        {
            return this.holder;
        }

        protected override void InnerAwake()
        {
            AddActionHandler<SetupItemProperties>(SetProperties);
        }

        protected override void InnerStart()
        {
            SelfInteract(new ExposeItemProperties(this));
        }

        private void SetProperties(SetupItemProperties action)
        {
            this.item = action.GetItem();
            this.itemEditorDetails = this.item.GetName();
            this.holder = action.GetHolder();
        }
    }
}
