Syndicator.Search.Constants = {}

local ClassData = {
  [1] = { -- Warrior
    {4, 4}, -- Plate
    {4, 6}, -- Shields
    {2, 0}, -- One-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 7}, -- One-Handed Swords
    {2, 15}, -- Daggers
    {2, 13}, -- Fist Weapons
    {2, 1}, -- Two-Handed Axes
    {2, 5}, -- Two-Handed Maces
    {2, 8}, -- Two-Handed Swords
    {2, 6}, -- Polearms
    {2, 10}, -- Staves
  },
  [2] = { -- Paladin
    {4, 4}, -- Plate
    {4, 6}, -- Shields
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 0}, -- One-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 7}, -- One-Handed Swords
    {2, 1}, -- Two-Handed Axes
    {2, 5}, -- Two-Handed Maces
    {2, 8}, -- Two-Handed Swords
    {2, 6}, -- Polearms
  },
  [3] = { -- Hunter
    {4, 3}, -- Mail
    {2, 2}, -- Bows
    {2, 18}, -- Crossbows
    {2, 3}, -- Guns
    {2, 6}, -- Polearms
    {2, 10}, -- Staves
    {2, 8}, -- Two-Handed Swords
    {2, 1}, -- Two-Handed Axes
  },
  [4] = { -- Rogue
    {4, 2}, -- Leather
    {2, 15}, -- Daggers
    {2, 13}, --Fist Weapons
    {2, 0}, -- One-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 7}, -- One-Handed Swords
  },
  [5] = { -- Priest
    {4, 1}, -- Cloth
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 15}, -- Daggers
    {2, 4}, -- One-Handed Maces
    {2, 10}, -- Staves
    {2, 19}, -- Wands
  },
  [6] = { -- Death Knight
    {4, 4}, -- Plate
    {2, 0}, -- One-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 7}, -- One-Handed Swords
    {2, 1}, -- Two-Handed Axes
    {2, 5}, -- Two-Handed Maces
    {2, 8}, -- Two-Handed Swords
    {2, 6}, -- Polearms
  },
  [7] = { -- Shaman
    {4, 3}, -- Mail
    {4, 6}, -- Shields
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 0}, -- One-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 15}, -- Daggers
    {2, 13}, --Fist Weapons
    {2, 10}, -- Staves
  },
  [8] = { -- Mage
    {4, 1}, -- Cloth
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 15}, -- Daggers
    {2, 7}, -- One-Handed Swords
    {2, 10}, -- Staves
    {2, 19}, -- Wands
  },
  [9] = { -- Warlock
    {4, 1}, -- Cloth
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 15}, -- Daggers
    {2, 7}, -- One-Handed Swords
    {2, 10}, -- Staves
    {2, 19}, -- Wands
  },
  [10] = { -- Monk
    {4, 2}, -- Leather
    {2, 13}, -- fist
    {2, 0}, -- One-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 7}, -- One-Handed Swords
    {2, 6}, -- Polearms
    {2, 10}, -- Staves
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
  },
  [11] = { -- Druid
    {4, 2}, -- Leather
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 4}, -- One-Handed Maces
    {2, 15}, -- Daggers
    {2, 13}, -- Fist Weapons
    {2, 12}, -- Cat Claws
    {2, 11}, -- Bear Claws
    {2, 5}, -- Two-Handed Maces
    {2, 6}, -- Polearms
    {2, 10}, -- Staves
  },
  [12] = { -- Demon Hunter
    {4, 2}, -- Leather
    {2, 0}, -- One-Handed Axes
    {2, 7}, -- One-Handed Swords
    {2, 9}, -- Warglaives
    {2, 15}, -- Daggers
    {2, 13}, -- Fist Weapons
  },
  [13] = { -- Evoker
    {4, 3}, -- Mail
    {4, 0, "INVTYPE_HOLDABLE"}, -- off hand
    {2, 15}, -- Daggers
    {2, 13}, -- Fist Weapons
    {2, 0}, -- One-Handed Axes
    {2, 1}, -- Two-Handed Axes
    {2, 4}, -- One-Handed Maces
    {2, 5}, -- Two-Handed Maces
    {2, 7}, -- One-Handed Swords
    {2, 8}, -- Two-Handed Swords
    {2, 10}, -- Staves
  }
}

Syndicator.Search.Constants.AllClassSpecializations = {}
for classID in ipairs(ClassData) do
  local index = 1
  local id
  while true do
    id = GetSpecializationInfoForClassID(classID, index)
    index = index + 1
    table.insert(Syndicator.Search.Constants.AllClassSpecializations, id)
    if id == nil then
      break
    end
  end
end

Syndicator.Search.Constants.ClassGear = {}

local currentClass = select(3, UnitClass("player"))

Syndicator.Search.Constants.ClassGear = {}
local classDetails = ClassData[currentClass]
for _, typeDetails in ipairs(classDetails) do
  Syndicator.Search.Constants.ClassGear[typeDetails[1]] = Syndicator.Search.Constants.ClassGear[typeDetails[1]] or {}
  Syndicator.Search.Constants.ClassGear[typeDetails[1]][typeDetails[2]] = Syndicator.Search.Constants.ClassGear[typeDetails[1]][typeDetails[2]] or {}
  if typeDetails[3] then
    Syndicator.Search.Constants.ClassGear[typeDetails[1]][typeDetails[2]][typeDetails[3]] = true
  end
end

Syndicator.Search.Constants.KeywordGroupOrder = {
  Syndicator.Locales.GROUP_ITEM_TYPE,
  Syndicator.Locales.GROUP_ITEM_DETAIL,
  Syndicator.Locales.GROUP_BINDING_TYPE,
  Syndicator.Locales.GROUP_QUALITY,

  Syndicator.Locales.GROUP_SLOT,
  Syndicator.Locales.GROUP_WEAPON_TYPE,
  Syndicator.Locales.GROUP_ARMOR_TYPE,
  Syndicator.Locales.GROUP_STAT,
  Syndicator.Locales.GROUP_SOCKET,

  Syndicator.Locales.GROUP_TRADE_GOODS,
  Syndicator.Locales.GROUP_RECIPE,
  Syndicator.Locales.GROUP_GLYPH,
  Syndicator.Locales.GROUP_CONSUMABLE,

  Syndicator.Locales.GROUP_EXPANSION,
  Syndicator.Locales.GROUP_BATTLE_PET,
  Syndicator.Locales.GROUP_HOUSING,
}

-- Special case for era because Blizzard doesn't tag the consumables or trade
-- goods by their subtype (and the subtype doesn't exist in era's data)
if Syndicator.Constants.IsEra then
  Syndicator.Search.Constants.TypeOverrides = {
    [0] = { -- Consumables
      [0] = {
        5514, 19697
      },
      [1] = { -- Potions
        3387, 9030, 13444, 13506, 5634, 13457, 5816, 9172, 2459, 13442, 929,
        13446, 3386, 13459, 13462, 3823, 13443, 1710, 13455, 20008, 3928, 18841,
        3827, 6149, 13458, 13461, 6052, 13456, 118, 5633, 858, 6048, 5631,
        13460, 6372, 3385, 1450, 18253, 17348, 6051, 12190, 6049, 4623, 18839,
        6050, 2455, 9144, 2456, 17351, 4596, 20002, 17352, 17349, 5632, 3087,
        23578, 23696, 23579, 23698
      },
      [2] = { -- Elixirs
        8410, 8411, 8412, 13452, 12820, 8529, 13454, 8423, 3825, 20007, 17708,
        3388, 9206, 9224, 8424, 20079, 5996, 21546, 13445, 9155, 9187, 3389,
        9088, 9264, 8949, 13447, 20004, 6373, 8951, 20081, 9179, 9197, 13453,
        3826, 9154, 2457, 3383, 6662, 10592, 3390, 3391, 8827, 2458, 3382,
        20080, 18294, 5997, 2454, 3828, 9233
      },
      [3] = { -- Flasks
        13512, 13510, 13511, 13513, 2593
      },
      [4] = { -- Scroll
        10309, 1180, 1477, 3013, 10310, 3012, 10305, 1181, 1478, 10306, 954,
        2289, 10307, 10308, 955, 1712, 2290, 4421, 4425, 1711, 4419, 4422, 4424,
        4426
      },
      [5] = { -- Food & Drink
        9260, 8932, 11951, 13755, 4536, 6522, 20452, 2596, 7676, 8079, 12217,
        13810, 21151, 13893, 2894, 13724, 13928, 13931, 8952, 6657, 4595, 21023,
        18254, 19301, 18255, 12238, 159, 4457, 3927, 3703, 422, 3770, 1179,
        9360, 11109, 13546, 4791, 8766, 17222, 21217, 20709, 16971, 1645, 16168,
        7228, 2594, 117, 18045, 8957, 6299, 8953, 12218, 21072, 5527, 23160,
        4593, 2595, 2687, 5525, 6887, 2684, 22895, 8364, 21114, 18632, 4541,
        4604, 6290, 18300, 2680, 4537, 4592, 4594, 5473, 13935, 4599, 13932,
        13927, 16766, 3771, 12210, 2683, 2287, 13934, 5479, 733, 1205, 1326,
        1708, 4539, 11415, 11846, 4608, 2681, 8948, 21721, 4605, 2686, 12216,
        4602, 5095, 5342, 20031, 8076, 12209, 18288, 4606, 9451, 10841, 12215,
        5478, 13851, 8078, 2679, 3726, 7808, 13929, 3666, 4538, 4600, 12213,
        17119, 414, 2070, 2136, 3665, 4601, 9361, 19221, 21033, 787, 1113, 3664,
        7097, 11584, 2723, 4607, 6888, 12214, 21552, 3728, 8950, 2288, 12212,
        17198, 19222, 1082, 3727, 5526, 12003, 13933, 19299, 3663, 4542, 5477,
        5480, 20074, 21031, 21215, 6890, 19224, 19225, 1707, 3729, 17197, 18287,
        3448, 3772, 8077, 11444, 12763, 4540, 5472, 5474, 17408, 1017, 1401,
        5066, 5349, 6038, 17406, 17407, 18633, 23172, 1114, 2888, 3662, 4544,
        4656, 6807, 8075, 13930, 16171, 19994, 3220, 6316, 12224, 19300, 20516,
        21030, 961, 1072, 1487, 5057, 12211, 16166, 16170, 17402, 17404, 19223,
        724, 1119, 5265, 5350, 7806, 7807, 19304, 19996, 21235, 21236, 21254,
        2682, 16167, 17196, 17403, 18635, 19305, 19306, 19995, 21240, 22324,
        5476, 8243, 8543, 9681, 16169, 17199, 17344, 19696, 2685
      },
      [6] = { -- Item Enhancement
        11647, 18330, 18329, 11645, 18169, 18283, 18182, 7969, 11642, 233802,
        15564, 11644, 6041, 6042, 20077, 12645, 4407, 18251, 11622, 238787,
        6043, 10548, 212568, 20076, 5421, 236324, 236326, 20078, 19787, 19785,
        18331, 19790, 19782, 235529, 243198, 19784, 19789, 7967, 4265, 231379,
        221321, 23548, 231362, 238786, 231367, 231370, 231383, 19788, 23545,
        236325, 19783, 4406, 231363, 236323, 231355, 19786, 10546, 221322,
        231359, 11648, 227926, 231381, 22635, 231357, 231361, 231366, 22638,
        18171, 2313, 231373, 231375, 2304, 22636, 11646, 231376, 238788, 8173,
        233803, 11643, 23547, 23549, 231372, 231354, 227819, 231384, 18170,
        4405, 18172, 231371, 231368, 231377, 231358, 18173, 221323, 22586,
        11649, 22022, 23725, 18666, 22042, 17897, 18599, 22032, 22020, 22587,
        17892, 17895, 17896, 11673, 17883, 22033, 22040, 17891, 22031, 22036,
        22041, 22043, 22588, 17827, 22035, 22038, 17894, 18668, 22025, 16104,
        22029, 22585, 231364, 11683, 17882, 17884, 22028, 11664, 11667, 17885,
        17887, 17899, 22024, 232343, 11663, 17828, 17829, 17830, 17893, 18667,
        18669, 22030, 22037, 22584, 23727, 23728, 11670, 11672, 11676, 17888,
        17898, 22021, 22023, 22034, 22039, 11666, 11671, 18262, 3829, 3824,
        233996, 12404, 20749, 20748, 236547, 20750, 6533, 236554, 236532, 6532,
        236520, 236555, 236549, 217345, 6947, 236504, 23122, 236481, 23123,
        236424, 236551, 6530, 226374, 236480, 236529, 236563, 236606, 3240,
        237810, 234444, 238241, 6949, 236608, 20747, 236548, 20746, 236460,
        6529, 236419, 12643, 236489, 236495, 236446, 236611, 210823, 236464,
        2863, 2892, 236552, 236421, 236620, 236601, 8928, 236516, 238234,
        236568, 231829, 236492, 3775, 236440, 236479, 236535, 236537, 236451,
        236604, 231828, 236435, 2862, 7964, 2871, 20744, 236578, 236447, 236585,
        226406, 236417, 6950, 211391, 236612, 221362, 226679, 236509, 236540,
        3776, 226418, 232611, 236569, 210820, 236594, 209852, 210818, 213123,
        226694, 236443, 236523, 10918, 236502, 20745, 226678, 236449, 236528,
        205947, 236472, 236484, 204441, 205022, 216606, 236437, 6811, 8926,
        203745, 204703, 206032, 206992, 226408, 236458, 5237, 20844, 236431,
        236470, 3241, 208778, 226407, 236467, 236496, 236603, 8927, 211385,
        221512, 226412, 236462, 203753, 203991, 204809, 208701, 210746, 221445,
        225687, 236575, 206970, 217736, 221513, 236459, 236577, 210654, 210817,
        210979, 211387, 211392, 211393, 236561, 236574, 236600, 7965, 8985,
        205897, 210980, 236518, 236588, 236615, 236617, 204912, 205685, 213120,
        221473, 226410, 226414, 236543, 236560, 7307, 10922, 210252, 211390,
        212549, 213124, 213125, 221480, 236432, 236455, 236544, 236566, 208771,
        210653, 236433, 236519, 236534, 236621, 9186, 203990, 203994, 204716,
        204795, 205950, 208741, 208777, 213086, 213128, 235602, 235605, 236478,
        236494, 236530, 205683, 208744, 211205, 220616, 221499, 226413, 228980,
        236508, 236623, 203752, 208687, 210015, 210500, 211386, 211488, 220164,
        221514, 223288, 225955, 236427, 236456, 236545, 236550, 204806, 206168,
        206169, 206989, 210824, 210825, 211490, 213093, 213098, 213129, 213599,
        220217, 220613, 221483, 235601, 236420, 236429, 236445, 236453, 236457,
        236463, 236505, 236556, 236590, 203747, 204174, 205945, 213101, 213115,
        213132, 221433, 221510, 221979, 225740, 226416, 236422, 236428, 236454,
        236461, 236473, 236475, 236498, 236589, 236592, 236598, 236602, 236619,
        6951, 208767, 210569, 211514, 213103, 213109, 213142, 220754, 226419,
        227456, 235604, 236423, 236442, 236466, 236474, 236477, 236503, 236507,
        236513, 236610, 205905, 206264, 206985, 210179, 210596, 211845, 213138,
        220612, 220791, 221267, 221428, 221515, 225914, 226587, 236487, 236511,
        236515, 236527, 236546, 236616, 203746, 205948, 205953, 205979, 206155,
        208750, 208758, 210137, 210589, 211848, 212551, 212559, 212561, 213100,
        213130, 213131, 219147, 220617, 221482, 226252, 226409, 226415, 226680,
        236450, 236482, 236497, 236512, 236526, 236567, 236570, 236587, 236613,
        236614, 203751, 208799, 210811, 212548, 212560, 213122, 213136, 213141,
        220360, 221489, 221980, 223147, 225686, 227922, 236425, 236426, 236500,
        236506, 236522, 236536, 236565, 236579, 236605, 8984, 10920, 203748,
        205228, 208772, 210322, 211476, 211530, 213092, 213096, 213117, 213144,
        217347, 220618, 221020, 221481, 221517, 226411, 226417, 227746, 227921,
        232461, 235598, 236444, 236468, 236471, 236491, 236517, 236521, 236524,
        236525, 236558, 236564, 236576, 236609, 3239, 203749, 203993, 205215,
        205230, 205940, 205944, 208754, 210573, 210822, 211477, 212550, 213074,
        213102, 213114, 213116, 220687, 221516, 227749, 228123, 232459, 235603,
        236430, 236436, 236438, 236493, 236499, 236501, 236510, 236531, 236539,
        236542, 236553, 236582, 236591, 236597, 202316, 205932, 205946, 205951,
        206963, 210655, 211531, 211691, 213090, 213104, 213111, 213118, 217346,
        220913, 221511, 221981, 225688, 225690, 225691, 235599, 235600, 236418,
        236434, 236439, 236469, 236476, 236538, 236557, 236571, 236573, 236580,
        236596, 236599, 5654, 10921, 205949, 208828, 208853, 209028, 210229,
        211301, 212562, 213119, 213137, 220610, 220614, 221461, 221490, 228124,
        228126, 235597, 236448, 236452, 236483, 236488, 236490, 236533, 236541,
        236581, 236583, 236593, 236595, 236618, 236622, 2893, 205943, 208753,
        212552, 213094, 213112, 213113, 213126, 213140, 213143, 220165, 221487,
        221488, 232460, 236441, 236465, 236514, 236559, 236562, 236584, 236586,
        205942, 208764, 208854, 213110, 213139, 220682, 225689, 236485, 236572,
        236607, 232458, 232462
      },
      [7] = { -- Bandages
        8545, 14529, 14530, 6450, 3531, 6451, 3530, 1251, 2581, 8544, 19307,
        20235, 20243, 19066, 20234, 20244, 19068, 20066, 20237, 20065, 20232,
        23684, 20067, 19067
      },
    },
    [7] = { -- Trade Goods
      [1] = { -- Parts
        18631, 4389, 16006, 15994, 10560, 238737, 16000, 7191, 10561, 4404,
        4371, 10558, 4382, 10505, 15992, 4363, 4377, 4399, 4375, 4387, 4359,
        4361, 10559, 4364, 4357, 4400, 215430, 234005
      },
      [2] = { -- Explosives
        10646, 4390, 10586, 4398, 10562, 18641, 15993, 10507, 4394, 18594, 4384,
        16040, 233985, 18588, 6714, 4852, 4395, 4367, 4378, 10514, 4380, 4365,
        4374, 16005, 4360, 4370, 4358, 233984, 215127, 233986, 215168, 221325,
        10580
      },
      [3] = { -- Devices
        4366, 18232, 4392, 15846, 16023, 5507, 11590, 4388, 11826, 18660, 4391,
        22728, 4376, 11825, 15996, 18645, 21277, 4386, 17716, 4403, 4401, 10719,
        20834, 18636, 6715
      },
      [5] = { -- Cloth
        14048, 14256, 14342, 2592, 3182, 4306, 14047, 4338, 14341, 14227, 2589,
        4339, 2320, 4305, 2321, 10285, 2997, 4337, 2996, 8343, 4291
      },
      [6] = { -- Leather
        15408, 8170, 15407, 8150, 15409, 12810, 8154, 4304, 8172, 4234, 2318,
        2319, 5784, 15417, 8167, 15416, 8165, 4461, 17012, 783, 4289, 4235,
        8169, 15410, 15414, 8171, 7392, 5785, 5082, 4233, 15412, 15419, 4232,
        4231, 2934, 4236, 7286, 15415, 20381, 19767, 19768, 17967
      },
      [7] = { -- Metal & Stone
        12360, 17771, 12644, 12359, 2836, 12655, 7912, 3858, 3859, 11371, 2838,
        10620, 12809, 18562, 11370, 2772, 12365, 2842, 2771, 3860, 22203, 2835,
        2775, 3857, 2841, 17203, 3575, 6037, 3486, 7966, 7911, 18567, 2770,
        2776, 2840, 3577, 3470, 22202, 3478, 3576, 11099, 3861
      },
      [8] = { -- Meat
        12207, 4603, 12203, 12184, 6362, 12202, 3404, 13759, 13888, 7974, 2677,
        6308, 3712, 5504, 8365, 21153, 21071, 13889, 12208, 13756, 12037, 12205,
        6291, 20424, 3685, 3174, 5503, 13760, 6289, 5465, 13754, 1468, 730,
        3667, 3731, 13758, 6361, 2674, 769, 2673, 3172, 2672, 1015, 3173, 2675,
        2251, 12206, 5469, 5471, 723, 3730, 6303, 5470, 729, 6889, 21024, 5466,
        1080, 2924, 4655, 2886, 8959, 12204, 12223, 731, 5467, 5468, 6317
      },
      [9] = { -- Herbs
        13468, 13463, 4625, 8846, 2452, 8153, 13466, 13465, 8838, 8845, 8839,
        3355, 13464, 3357, 3818, 3820, 8831, 13467, 3821, 3369, 3819, 8836,
        2450, 2449, 19726, 3356, 2453, 3358, 785, 2447, 765, 19727
      },
      [10] = { -- Elemental
        7078, 7067, 7080, 7068, 7082, 7069, 12808, 7070, 12803, 10286, 7076,
        7077, 7079, 7972, 7075, 7081
      },
      [12] = { -- Enchanting
        16203, 14344, 11176, 11177, 20725, 16204, 11137, 11083, 16202, 10940,
        10998, 11178, 11175, 11174, 10938, 11082, 10939, 14343, 774, 11135,
        11139, 11134, 10978, 11084, 11138
      },
    },
    [13] = {
      [0] = { 232077 }, -- Wand of Making
    }
  }

  Syndicator.Search.Constants.TypeOverridesMap = {}
  for classID, subClasses in pairs(Syndicator.Search.Constants.TypeOverrides) do
    for subClassID, items in pairs(subClasses) do
      for _, itemID in ipairs(items) do
        Syndicator.Search.Constants.TypeOverridesMap[itemID] = {classID = classID, subClassID = subClassID}
      end
    end
  end
end
