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

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

-- AucItemClasses
local Class_Weapon					=select(1, GetAuctionItemClasses())
local Class_Armor					=select(2, GetAuctionItemClasses())
local Class_Recipe					=select(7, GetAuctionItemClasses())

-- AucItemSubClasses
local SubClass_Parts				=select(9, GetAuctionItemSubClasses(6))
local SubClass_Materials			=select(4, GetAuctionItemSubClasses(6))
local SubClass_Recipe_Blacksmithing	=select(5, GetAuctionItemSubClasses(7))
local SubClass_Other				=select(5, GetAuctionItemSubClasses(9))

-- Tab Names
local TN={}
TN.Blacksmithing=SubClass_Recipe_Blacksmithing
TN.All=ALL 								-- Источник==Кузнечное дело ИЛИ Используется==Кузнечное дело или Рецепт
-- Материалы
TN.Materials=SubClass_Materials 		-- Мтеалл и камни
TN.Parts=SubClass_Parts			 		-- Используется==Кузнечном деле И НЕ Металл и камни
-- Продукты
TN.Weapons=Class_Weapon					-- Изготовленное Оружие
TN.Armors=Class_Armor					-- Изготовленная Броня
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 isBlacksmithing(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 (ReagentsForBlacksmithing[tonumber(ItemID)] or CraftedByBlacksmithing[tonumber(ItemID)] or subType==SubClass_Recipe_Blacksmithing or subType==SubClass_Materials)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isMaterial(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not subType then return false end

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

	return (subType==SubClass_Materials)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isPart(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 (ReagentsForBlacksmithing[tonumber(ItemID)] and subType~=SubClass_Materials)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isProduct(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not link then return false end
	if not type then return false end

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

	return (CraftedByBlacksmithing[tonumber(ItemID)] and type~=Class_Weapon and type~=Class_Armor)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isWeapon(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	
	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end
	
	return (CraftedByBlacksmithing[tonumber(ItemID)] and type==Class_Weapon)
end
-----------------------------------------------------------------------------------------------------------------------------------------
local function isArmor(player, bagType, name, link, quality, level, ilvl, type, subType, stackCount, equipLoc)
	if not type then return false end
	
	local ItemID=GetItemIDFromLink(link)
	if not ItemID then return false end
	
	return (CraftedByBlacksmithing[tonumber(ItemID)] and type==Class_Armor)
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_Blacksmithing)
end
-----------------------------------------------------------------------------------------------------------------------------------------
CombuctorSet:Register(TN.Blacksmithing, IconPathName, isBlacksmithing)

CombuctorSet:RegisterSubSet(TN.All,			TN.Blacksmithing,nil,isBlacksmithing)
CombuctorSet:RegisterSubSet(TN.Materials,	TN.Blacksmithing,nil,isMaterial)
CombuctorSet:RegisterSubSet(TN.Parts,		TN.Blacksmithing,nil,isPart)
CombuctorSet:RegisterSubSet(TN.Weapons,		TN.Blacksmithing,nil,isWeapon)
CombuctorSet:RegisterSubSet(TN.Armors,		TN.Blacksmithing,nil,isArmor)
CombuctorSet:RegisterSubSet(TN.Products,	TN.Blacksmithing,nil,isProduct)
CombuctorSet:RegisterSubSet(TN.Recipes,		TN.Blacksmithing,nil,isRecipe)
