using MapleLib.WzLib.WzStructure.Data.ItemStructure;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HaCreator.GUI.Quest
{
    public class QuestEditorCheckItemReqModel : INotifyPropertyChanged
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public QuestEditorCheckItemReqModel()
        {
        }

        private int _itemId;
        /// <summary>
        /// The itemId of the item to give
        /// </summary>
        public int ItemId
        {
            get { return _itemId; }
            set
            {
                this._itemId = value;
                OnPropertyChanged(nameof(ItemId));
            }
        }

        private int _quantity;
        /// <summary>
        /// The quantity of the item to give. Negative is to take.
        /// </summary>
        public int Quantity
        {
            get { return _quantity; }
            set
            {
                int newValue = value;

                if (newValue == 0) // dont allow 0
                    newValue = 1;

                if (ItemIdsCategory.IsEquipment(_itemId))  // Restrict to -1 or 1 if IsEquip is true
                    newValue = Math.Sign(newValue);
                else // Clamp between -9999 and 9999 if IsEquip is false
                    newValue = Math.Max(-9999, Math.Min(9999, newValue));

                this._quantity = newValue;
                OnPropertyChanged(nameof(Quantity));
            }
        }

        #region Property Changed Event
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}
