-- REQUIRED Combuctor
local CombuctorSet = Combuctor:GetModule("Sets")

-- Profession Icon Name
local IconPathName="Interface/Icons/Trade_engraving"

-- AucItemClasses
local Class_TradeGoods				=select(6, GetAuctionItemClasses()) -- Хозяйственные товары
local Class_Recipe					=select(7, GetAuctionItemClasses()) -- Рецепты

-- AucItemSubClasses
local SubClass_Materials			=select(12, GetAuctionItemSubClasses(6)) -- Хозяйственные товары\Материалы
local SubClass_TradeGoodsEnchanting =select(7, GetAuctionItemSubClasses(6))  -- Хозяйственные товары\Наложение чар
local SubClass_Reagents				=select(2, GetAuctionItemSubClasses(9)) -- Разное\Реагенты

local SubClass_ItemEnchantment		=select(6, GetAuctionItemSubClasses(4))  -- Расходуемые\Улучшения
local SubClass_Other				=select(5, GetAuctionItemSubClasses(9)) -- Разное\Другое

local SubClass_Recipe_Enchanting	=select(9, GetAuctionItemSubClasses(7))  -- Рецепты\Наложение чар

-- Tab Names
local TN={}
TN.Enchanting=SubClass_Recipe_Enchanting
TN.All=ALL 									-- Источник==Наложенеи чар ИЛИ Используется==Наложение чар дело ИЛИ Рецепт
-- Материалы
TN.Materials=SubClass_TradeGoodsEnchanting	-- Хозяйственные товары\Наложение чар
TN.Reagents=SubClass_Reagents				-- РеагентыДляНаложенияЧар И НЕ Хозяйственные товары\Наложение чар  
-- Продукты
TN.ItemEnchantment=SubClass_ItemEnchantment	-- Чары для оружия и/или брони
TN.Products=SubClass_Other					-- Источник==Наложение чар И НЕ Чары
-- Рецепты
TN.Recipes=Class_Recipe						-- Рецепты 
-----------------------------------------------------------------------------------------------------------------------------------------
local function GetItemIDFromLink(itemLink)
	if not itemLink or itemLink=="" then return nil end

	local itemString = string.match(itemLink, "item[%-?%d:]+")
	local linkType, itemId, enchantId,jewelId1, jewelId2, jewelId3, jewelId4,suffixId, uniqueId = strsplit(":", itemString)
	if (linkType == 'item') then
		return itemId
	end
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isEnchanting(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end
	if not subType then return false end

	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (subType==SubClass_TradeGoodsEnchanting or subType == SubClass_ItemEnchantment or ReagentsForEnchanting[tonumber(ItemID)] or CraftedByEnchanting[tonumber(ItemID)] or subType==SubClass_Recipe_Enchanting)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isMaterial(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	if not subType then return false end
	return (type==Class_TradeGoods and subType==SubClass_TradeGoodsEnchanting)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isReagent(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end

	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (ReagentsForEnchanting[tonumber(ItemID)] and isMaterial(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)==false)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isItemEnchantment(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end
	return (subType == SubClass_ItemEnchantment)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isProduct(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end
	if not subType then return false end

	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end

	return (CraftedByEnchanting[tonumber(ItemID)] and subType~=SubClass_ItemEnchantment)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isRecipe(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	if not subType then return false end
	return (type==Class_Recipe and subType==SubClass_Recipe_Enchanting)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Enchanting, IconPathName, isEnchanting)

CombuctorSet:RegisterSubSet(TN.All,				TN.Enchanting,nil,isEnchanting)
CombuctorSet:RegisterSubSet(TN.Materials,		TN.Enchanting,nil,isMaterial)
CombuctorSet:RegisterSubSet(TN.Reagents,		TN.Enchanting,nil,isReagent)
CombuctorSet:RegisterSubSet(TN.ItemEnchantment,	TN.Enchanting,nil,isItemEnchantment)
CombuctorSet:RegisterSubSet(TN.Products,		TN.Enchanting,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,			TN.Enchanting,nil,isRecipe)
