using Framework.ItemSystem;
using Testing.ItemSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Testing.Root;
using UnityEngine;

namespace Framework.ItemSystem
{
    public partial class ItemType
    {
        public static readonly Id TestType = Allocate((definition, owner) => { return new TestItem(definition, owner); });
    }
}

namespace Testing.ItemSystem
{
    public class TestItem : Item
    {
        public TestItem(ItemDefinitionlike definition, GameObject owner)
            : base(definition, owner)
        {
        }

        public override void EnterInventory()
        {
            throw new NotImplementedException();
        }

        public override void LeaveInventory()
        {
            throw new NotImplementedException();
        }
    }

    public class ItemDefinitionTests : Tests
    {
        ItemDefinition itemDefinition;

        public ItemDefinitionTests()
        {
            ItemDefinitionsLocator.Get().AddItemDefinition(new ItemDefinition("Test", ItemType.Example, "Test item."));
            ItemDefinitionsLocator.Get().AddItemDefinition(new ItemDefinition("Test2", ItemType.TestType, "Test item 2."));
        }

        public void Setup()
        {
            itemDefinition = (ItemDefinition)ItemDefinitionsLocator.Get().GetItemDefinition("Test");
        }

        public void Shutdown()
        {
            this.itemDefinition = null;
        }

        public void CreateItemInstanceTest()
        {
            GameObject gameObject = new GameObject();
            gameObject.name = "CreateItemInstanceTest Object";
            Itemlike item = this.itemDefinition.CreateItemInstance(gameObject);
            Assert(item != null, "Item not null");
            Assert(item.GetType(), typeof(Item), "Item is type of ExampleItem");
        }

        public void CreateItemInstanceTest_Alternate()
        {
            ItemDefinitionlike itemDefinition2 = ItemDefinitionsLocator.Get().GetItemDefinition("Test2");
            GameObject gameObject = new GameObject();
            gameObject.name = "CreateItemInstanceTest_Alternative Object";
            Itemlike item = itemDefinition2.CreateItemInstance(gameObject);
            Assert(item != null, "Item not null");
            Assert(item.GetType(), typeof(TestItem), "Item is type of TestItem");
        }
    }
}
