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

namespace Framework.ItemSystem
{
    /// <summary>
    /// An item definition contains general data for a specific 
    /// item 'class' as opposed to a specific item instance. The 
    /// definition is utilised as a flyweight. Item definitions
    /// should be loaded from disk or constructed in a lookup
    /// table.
    /// </summary>
    public class ItemDefinition : ItemDefinitionlike
    {
        private string name; // The name of the itme
        private ItemType.Id type; // The type of the item as an ItemType
        private string description; // The deescription of the item

        public ItemDefinition()
        {
        }

        /// <summary>
        /// Instantiates an item definition.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="description"></param>
        public ItemDefinition(string name, ItemType.Id type, string description)
        {
            this.name = name;
            this.type = type;
            this.description = description;
        }

        /// <summary>
        /// Gets the name of this item.
        /// </summary>
        /// <returns></returns>
        public string GetName()
        {
            return this.name;
        }

        /// <summary>
        /// Gets the type of this item, identified by a <see cref="ItemType.Id"/>.
        /// </summary>
        /// <returns></returns>
        public ItemType.Id GetItemType()
        {
            return type;
        }

        /// <summary>
        /// Gets the description of this item.
        /// </summary>
        /// <returns></returns>
        public string GetDescription()
        {
            return this.description;
        }
        
        /// <summary>
        /// Creates an instance of a item with this defintion and given item type.
        /// </summary>
        /// <typeparam name="ItemType"></typeparam>
        /// <param name="owner"></param>
        /// <returns></returns>
        public Itemlike CreateItemInstance(GameObject owner)
        {
            return this.type.CreateItem(this, owner);
        }
    }
}
