﻿
using UnityEngine;
using ORKFramework.Events;
using UltimateSurvival;
using System.Collections.Generic;
using System.Text;

namespace ORKFramework.UltimateSurvival
{
	public class UltimateSurvivalItem : BaseData
	{
		// item name
		[ORKEditorInfo(labelText="Item Name", label=new string[]
		{
			"Must match the name of the Ultimate Survival item that will be used."
		})]
		public StringValue name = new StringValue();


		// item quantity
		[ORKEditorInfo(separator=true, labelText="Quantity")]
		public EventInteger quantity = new EventInteger(1);

		public UltimateSurvivalItem()
		{

		}

		public void Add(InventoryController inventory, BaseEvent baseEvent)
		{
			if(inventory != null)
			{
				int tmp = -1;
				inventory.AddItemToCollection(
					this.name.GetValue(),
					this.quantity.GetValue(baseEvent),
					"Inventory", out tmp);
			}
		}

		public void Remove(InventoryController inventory, BaseEvent baseEvent)
		{
			if(inventory != null)
			{
				inventory.RemoveItems(
					this.name.GetValue(),
					this.quantity.GetValue(baseEvent));
			}
		}

		public bool Has(InventoryController inventory, BaseEvent baseEvent)
		{
			if(inventory != null)
			{
				return this.quantity.GetValue(baseEvent) <= inventory.GetItemCount(this.name.GetValue());
			}
			return false;
		}

		public bool HasExact(InventoryController inventory, BaseEvent baseEvent)
		{
			if(inventory != null)
			{
				return this.quantity.GetValue(baseEvent) == inventory.GetItemCount(this.name.GetValue());
			}
			return false;
		}

		public void GetInfoText(StringBuilder builder)
		{
			builder.Append(this.name.GetInfoText()).Append(" ").
				Append(this.quantity.GetInfoText());
		}
	}
}
