local _, ns = ...

ns.staticPromotionItems = ns.staticPromotionItems or {
  { itemID = 256764, sourceName = "In-Game Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 259055, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259056, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259057, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259058, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259059, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259060, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259061, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259062, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259063, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259064, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259065, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259066, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259067, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259068, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259069, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 259070, sourceName = "Promotional", sourceDetail = "Diablo IV: Lord of Hatred", expansion = "Other" },
  { itemID = 260727, sourceName = "In-Game Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 260728, sourceName = "In-Game Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 263052, sourceName = "In-Game Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 263053, sourceName = "In-Game Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 263301, sourceName = "Promotional", sourceDetail = "", expansion = "Other" },
  { itemID = 264281, sourceName = "Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 264283, sourceName = "Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 264384, sourceName = "Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 264396, sourceName = "Shop", sourceDetail = "", expansion = "Other" },
  { itemID = 264397, sourceName = "Shop", sourceDetail = "", expansion = "Other" },
}

do
  ns.baseProfessionData = ns.baseProfessionData or {}

  local professionAdds = {
    {
      expansion = "Midnight",
      profession = "Unknown Profession",
      decorations = {
        {
          itemID = 253497,
          name = "Rootbound Vat",
          source = "Unknown Profession",
          recipeKnown = false,
          resources = {},
        },
      },
    },
    {
      expansion = "Cataclysm",
      profession = "Tailoring",
      decorations = {
        {
          itemID = 257402,
          name = "\"Unity of Thorns\" Tapestry",
          source = "Tailoring",
          recipeID = 1262370,
          recipeKnown = false,
          resources = {
            { itemID = 251764, quantity = 26 },
            { itemID = 54440, quantity = 2 },
            { itemID = 54849, quantity = 2 },
            { itemID = 38426, quantity = 8 },
            { itemID = 61981, quantity = 6 },
          },
        },
      },
    },
    {
      expansion = "Midnight",
      profession = "Unknown Profession",
      decorations = {
        {
          itemID = 262789,
          name = "Small Telogrus Lamp",
          source = "Unknown Profession",
          recipeKnown = false,
          resources = {},
        },
      },
    },
  }

  local knownProfessionItems = {}
  for _, entry in ipairs(ns.baseProfessionData) do
    for _, item in ipairs((type(entry) == "table" and entry.decorations) or {}) do
      local itemID = tonumber(type(item) == "table" and item.itemID) or 0
      if itemID > 0 then
        knownProfessionItems[itemID] = true
      end
    end
  end

  for _, entry in ipairs(professionAdds) do
    local filtered = {}
    for _, item in ipairs(entry.decorations or {}) do
      local itemID = tonumber(type(item) == "table" and item.itemID) or 0
      if itemID > 0 and not knownProfessionItems[itemID] then
        filtered[#filtered + 1] = item
        knownProfessionItems[itemID] = true
      end
    end
    if #filtered > 0 then
      entry.decorations = filtered
      ns.baseProfessionData[#ns.baseProfessionData + 1] = entry
    end
  end
end

do
  if type(ns.staticAcquireData) ~= "table" then
    return
  end

  local groupsByMode = ns.staticAcquireData.groupsByMode
  if type(groupsByMode) ~= "table" then
    return
  end
  groupsByMode.vendor = groupsByMode.vendor or {}

  local knownVendorItems = {}
  for _, group in ipairs(groupsByMode.vendor) do
    for _, row in ipairs((type(group) == "table" and group.items) or {}) do
      local itemID = tonumber(type(row) == "table" and row.itemID) or 0
      if itemID > 0 then
        knownVendorItems[itemID] = true
      end
    end
  end

  local vendorGroups = {
    {
      key = "other|world vendors|unknown zone||0|vendor",
      mode = "vendor",
      category = "Vendor",
      expansion = "Other",
      label = "World Vendors",
      detail = "Unknown Zone",
      items = {
        { itemID = 263383, sourceType = 5, sourceName = "World Vendors", sourceDetail = "", source = "World Vendors", category = "Vendor", expansion = "Other", zone = "Unknown Zone", acquireStatus = "Vendor", purchaseCosts = {} },
        { itemID = 264278, sourceType = 5, sourceName = "World Vendors", sourceDetail = "", source = "World Vendors", category = "Vendor", expansion = "Other", zone = "Unknown Zone", acquireStatus = "Vendor", purchaseCosts = {} },
        { itemID = 264279, sourceType = 5, sourceName = "World Vendors", sourceDetail = "", source = "World Vendors", category = "Vendor", expansion = "Other", zone = "Unknown Zone", acquireStatus = "Vendor", purchaseCosts = {} },
        { itemID = 264280, sourceType = 5, sourceName = "World Vendors", sourceDetail = "", source = "World Vendors", category = "Vendor", expansion = "Other", zone = "Unknown Zone", acquireStatus = "Vendor", purchaseCosts = {} },
      },
    },
    {
      key = "midnight|unknown vendor|midnight||0|vendor",
      mode = "vendor",
      category = "Vendor",
      expansion = "Midnight",
      label = "Unknown Vendor",
      detail = "Midnight",
      items = {
        { itemID = 265653, sourceType = 5, sourceName = "Unknown Vendor", sourceDetail = "Midnight", source = "Unknown Vendor", category = "Vendor", expansion = "Midnight", zone = "Midnight", acquireStatus = "Vendor", purchaseCosts = {} },
        { itemID = 265654, sourceType = 5, sourceName = "Unknown Vendor", sourceDetail = "Midnight", source = "Unknown Vendor", category = "Vendor", expansion = "Midnight", zone = "Midnight", acquireStatus = "Vendor", purchaseCosts = {} },
        { itemID = 266064, sourceType = 5, sourceName = "Unknown Vendor", sourceDetail = "Midnight", source = "Unknown Vendor", category = "Vendor", expansion = "Midnight", zone = "Midnight", acquireStatus = "Vendor", purchaseCosts = {} },
        { itemID = 266130, sourceType = 5, sourceName = "Unknown Vendor", sourceDetail = "Midnight", source = "Unknown Vendor", category = "Vendor", expansion = "Midnight", zone = "Midnight", acquireStatus = "Vendor", purchaseCosts = {} },
      },
    },
  }

  for _, group in ipairs(vendorGroups) do
    local filtered = {}
    for _, row in ipairs(group.items or {}) do
      local itemID = tonumber(type(row) == "table" and row.itemID) or 0
      if itemID > 0 and not knownVendorItems[itemID] then
        filtered[#filtered + 1] = row
        knownVendorItems[itemID] = true
      end
    end
    if #filtered > 0 then
      group.items = filtered
      groupsByMode.vendor[#groupsByMode.vendor + 1] = group
    end
  end
end
