using System;
using EFT.InventoryLogic;
using stupid.solutions;
using stupid.solutions.Data;
using stupid.solutions.Utils;

namespace stupid.solutions.stupid.solutions.Data;

public class ContainerItem
{
	public Item Item { get; }

	public string ItemID { get; private set; }

	public string LocalizedName { get; private set; }

	public string ShortName { get; private set; }

	public ItemCategories Itemcat { get; private set; }

	public int? itemprice { get; private set; }

	public int Count { get; set; } = 1;

	public ContainerItem(Item lootItem)
	{
		if (lootItem == null)
		{
			throw new ArgumentNullException("lootItem");
		}
		Item = lootItem;
		LocalizedName = string.Empty;
		ItemID = string.Empty;
		ShortName = string.Empty;
		Itemcat = ItemCategories.Uninitialized;
		itemprice = null;
		Count = 1;
	}

	public void CalculateItemPrice()
	{
		if (Item == null)
			return;

		if (Item.Template == null)
			return;

		itemprice = GameUtils.GetItemPriceBYID(Item.TemplateId) * Count;
	}

	public void SetItemCat()
	{
        if (Item == null)
            return;

        if (Item.Template == null)
            return;

        string text = Item.LocalizedName();
		string item = Item.TemplateId;
		if (QuestESP.QuestItemIds.Contains(text))
		{
			Itemcat = ItemCategories.Quest;
			return;
		}
		if (Main.IsSuperrare(text))
		{
			Itemcat = ItemCategories.Superrare;
			return;
        }
		if (Main.IsKappa(text))
		{
			Itemcat = ItemCategories.Kappa;
			return;
        }
		if (Main.IsStim(text))
		{
			Itemcat = ItemCategories.Stim;
			return;
        }
		if (Main.SearchedItem(text))
		{
			Itemcat = ItemCategories.Searched;
			return;
        }
		if (Main.wishlistitemids.Contains(item))
		{
			Itemcat = ItemCategories.Wishlist;
			return;
		}
		if (Main.hideoutitemids.Contains(item))
		{
			Itemcat = ItemCategories.Hideout;
			return;
        }

		Itemcat = ItemCategories.Common;
	}

	public bool IsSameItem(ContainerItem other)
	{
		if (other == null)
			return false;

		return ItemID == other.ItemID;
	}

	public void RecalculateDynamics()
	{
        if (Item == null)
            return;

        if (Item.Template == null)
            return;

        if (string.IsNullOrEmpty(LocalizedName))
            LocalizedName = Item.LocalizedName();

		if (string.IsNullOrEmpty(ItemID))
			ItemID = Item.TemplateId.ToString();

		if (string.IsNullOrEmpty(ShortName))
			ShortName = Item.ShortName.Localized();
	}
}
