package ru.dbotthepony.mc.otm.datagen.advancements

import net.minecraft.advancements.Advancement
import net.minecraft.advancements.FrameType
import net.minecraft.advancements.critereon.ItemPredicate
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraftforge.common.data.ExistingFileHelper
import ru.dbotthepony.mc.otm.datagen.lang.MatteryLanguageProvider
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.registry.MItems
import ru.dbotthepony.mc.otm.triggers.ExopackBatterySlotTrigger
import ru.dbotthepony.mc.otm.triggers.ExopackGainedCraftingTrigger
import ru.dbotthepony.mc.otm.triggers.ExopackGainedSmeltingTrigger
import ru.dbotthepony.mc.otm.triggers.ExopackObtainedTrigger
import ru.dbotthepony.mc.otm.triggers.ExopackSlotsExpandedTrigger
import java.util.function.Consumer

fun addExopackAdvancements(serializer: Consumer<Advancement>, existingFileHelper: ExistingFileHelper, lang: MatteryLanguageProvider, root: Advancement, zpm: Advancement) {
	val translation = lang.MultiBuilder("otm.advancements.exopack")

	AdvancementBuilder()
		.parent(zpm)
		.display(
			hidden = true,
			itemStack = ItemStack(MItems.ZPM_BATTERY),
			title = translation.add("zpm_battery", "At Maximum Battery Capacity") {
				russian("Достигнут максимальный заряд батареи")
			},
			description = translation.add("zpm_battery.desc", "Use Zero Point Module as power source in Exopack") {
				russian("Используйте модуль нулевой точки как источник питания в Экзопаке")
			},
			frameType = FrameType.GOAL
		)
		.addCriterion("zpm_battery", ExopackBatterySlotTrigger.Instance(ItemPredicate.Builder.item().of(MItems.ZPM_BATTERY).build()))
		.save(serializer, modLocation("exopack/zpm_battery"), existingFileHelper)

	val obtained = AdvancementBuilder()
		.parent(root)
		.display(
			itemStack = ItemStack(MItems.EXOPACK_PROBE),
			title = translation.add("obtained", "One Dimension Bigger") {
				russian("Больше на одно измерение")
			},
			description = translation.add("obtained.desc", "Obtain an Exopack, a mysterious, semi-present, light as a feather, stuff storage on your back") {
				russian("Получите Экзопак, загадочное, полу-присутствующее, лёгкое как пёрышко, хранилище штуковин на вашей спине")
			},
			frameType = FrameType.GOAL
		)
		.addCriterion("obtained", ExopackObtainedTrigger.instance)
		.save(serializer, modLocation("exopack/obtained"), existingFileHelper)

	AdvancementBuilder()
		.parent(obtained)
		.display(
			itemStack = ItemStack(Items.CRAFTING_TABLE),
			title = translation.add("crafting", "Crafting on Go") {
				russian("Крафт по пути")
			},
			description = translation.add("crafting.desc", "Install Crafting Upgrade in your Exopack, allowing to craft 3x3 recipes") {
				russian("Установите улучшение сетки крафта в ваш Экзопаке, который позволяет создавать предметы, требующие сетку крафта рабочего стола")
			},
		)
		.addCriterion("crafting", ExopackGainedCraftingTrigger.instance)
		.save(serializer, modLocation("exopack/crafting"), existingFileHelper)

	AdvancementBuilder()
		.parent(obtained)
		.display(
			itemStack = ItemStack(Items.FURNACE),
			title = translation.add("smelting", "Pocket Furnace") {
				russian("Печь в кармане")
			},
			description = translation.add("smelting.desc", "Install Smelting Module in your Exopack, allowing to smelt items right inside your inventory") {
				russian("Установите модуль переплавки в ваш Экзопак, позволяющий переплавлять предметы прямо у вас в инвентаре")
			},
		)
		.addCriterion("smelting", ExopackGainedSmeltingTrigger.instance)
		.save(serializer, modLocation("exopack/smelting"), existingFileHelper)

	var size = AdvancementBuilder()
		.parent(obtained)
		.display(
			itemStack = ItemStack(Items.CHEST),
			title = translation.add("size0", "Closet Upgrade") {
				russian("Обновление чуланчика")
			},
			description = translation.add("size0.desc", "Upgrade Exopack storage") {
				russian("Улучшите размер инвентаря Экзопака")
			},
		)
		.addCriterion("size0", ExopackSlotsExpandedTrigger.Instance(minTotal = 1))
		.save(serializer, modLocation("exopack/size0"), existingFileHelper)

	val size0 = size

	size = AdvancementBuilder()
		.parent(size)
		.display(
			itemStack = ItemStack(Items.CHEST),
			title = translation.add("size1", "Double the Capacity") {
				russian("Двойной объём")
			},
			description = translation.add("size1.desc", "Reach 27 slots in your Exopack storage") {
				russian("Достигните 27 слотов хранилища Экзопака")
			},
		)
		.addCriterion("size1", ExopackSlotsExpandedTrigger.Instance(minTotal = 27))
		.save(serializer, modLocation("exopack/size1"), existingFileHelper)

	size = AdvancementBuilder()
		.parent(size)
		.display(
			itemStack = ItemStack(Items.CHEST),
			hidden = true,
			title = translation.add("size2", "Pack Rat") {
				russian("Воришка")
			},
			description = translation.add("size2.desc", "Reach 54 slots in your Exopack storage") {
				russian("Достигните 54 слотов хранилища Экзопака")
			},
		)
		.addCriterion("size2", ExopackSlotsExpandedTrigger.Instance(minTotal = 54))
		.save(serializer, modLocation("exopack/size2"), existingFileHelper)

	size = AdvancementBuilder()
		.parent(size)
		.display(
			itemStack = ItemStack(Items.CHEST),
			hidden = true,
			title = translation.add("size3", "Its Getting Big In Here") {
				russian("Тут становится просторно")
			},
			description = translation.add("size3.desc", "Reach 108 slots in your Exopack storage") {
				russian("Достигните 108 слотов хранилища Экзопака")
			},
			frameType = FrameType.GOAL
		)
		.addCriterion("size3", ExopackSlotsExpandedTrigger.Instance(minTotal = 108))
		.save(serializer, modLocation("exopack/size3"), existingFileHelper)

	size = AdvancementBuilder()
		.parent(size)
		.display(
			itemStack = ItemStack(Items.ENDER_CHEST),
			hidden = true,
			title = translation.add("size4", "Warehousing Pioneer") {
				russian("Пионер складских решений")
			},
			description = translation.add("size4.desc", "Reach 432 slots in your Exopack storage. You could fit a house in there") {
				russian("Достигните 432 слотов хранилища Экзопака. Туда можно уже впихнуть целый дом")
			},
			frameType = FrameType.CHALLENGE
		)
		.addCriterion("size4", ExopackSlotsExpandedTrigger.Instance(minTotal = 432))
		.save(serializer, modLocation("exopack/size4"), existingFileHelper)

	AdvancementBuilder()
		.parent(size)
		.display(
			itemStack = ItemStack(Items.ENDER_CHEST),
			hidden = true,
			title = translation.add("size5", "With Volume Like This...") {
				russian("С таким объёмом...")
			},
			description = translation.add("size5.desc", "Reach 1728 slots in your Exopack storage. Why would you need to go any bigger?!") {
				russian("Достигните 1728 слотов хранилища Экзопака. Куда вам столько?!")
			},
			frameType = FrameType.CHALLENGE
		)
		.addCriterion("size5", ExopackSlotsExpandedTrigger.Instance(minTotal = 1728))
		.save(serializer, modLocation("exopack/size5"), existingFileHelper)

	var once = AdvancementBuilder()
		.parent(size0)
		.display(
			itemStack = ItemStack(Items.CHEST),
			title = translation.add("once0", "One Module - One Row") {
				russian("Один модуль - одна строка")
			},
			description = translation.add("once0.desc", "Upgrade your Exopack storage with 9 slots using one module") {
				russian("Улучшите хранилище Экзопака модулем на 9 слотов")
			},
		)
		.addCriterion("once0", ExopackSlotsExpandedTrigger.Instance(minGained = 9))
		.save(serializer, modLocation("exopack/once0"), existingFileHelper)

	once = AdvancementBuilder()
		.parent(once)
		.display(
			itemStack = ItemStack(Items.CHEST),
			title = translation.add("once1", "One Module - One Chest") {
				russian("Один модуль - один сундук")
			},
			description = translation.add("once1.desc", "Upgrade your Exopack storage with 27 slots using one module") {
				russian("Улучшите хранилище Экзопака модулем на 27 слотов")
			},
		)
		.addCriterion("once1", ExopackSlotsExpandedTrigger.Instance(minGained = 27))
		.save(serializer, modLocation("exopack/once1"), existingFileHelper)

	once = AdvancementBuilder()
		.parent(once)
		.display(
			itemStack = ItemStack(Items.CHEST),
			hidden = true,
			title = translation.add("once2", "One Module - Two Chests?") {
				russian("Один модуль - два сундука?")
			},
			description = translation.add("once2.desc", "Upgrade your Exopack storage with 54 slots using one module") {
				russian("Улучшите хранилище Экзопака модулем на 54 слотов")
			},
			frameType = FrameType.GOAL
		)
		.addCriterion("once2", ExopackSlotsExpandedTrigger.Instance(minGained = 54))
		.save(serializer, modLocation("exopack/once2"), existingFileHelper)

	once = AdvancementBuilder()
		.parent(once)
		.display(
			itemStack = ItemStack(Items.ENDER_CHEST),
			hidden = true,
			title = translation.add("once3", "Storage Housing Construct") {
				russian("Хранилище быстрого приготовления")
			},
			description = translation.add("once3.desc", "Upgrade your Exopack storage with 90 slots using one module") {
				russian("Улучшите хранилище Экзопака модулем на 90 слотов")
			},
			frameType = FrameType.GOAL
		)
		.addCriterion("once3", ExopackSlotsExpandedTrigger.Instance(minGained = 90))
		.save(serializer, modLocation("exopack/once3"), existingFileHelper)

	AdvancementBuilder()
		.parent(once)
		.display(
			itemStack = ItemStack(Items.ENDER_CHEST),
			hidden = true,
			title = translation.add("once4", "Non-Euclidean Wardrobe") {
				russian("Неевклидов Шкаф")
			},
			description = translation.add("once4.desc", "Upgrade your Exopack storage with 150 slots using one module. After you open one, tens meters long racks roll out of it!") {
				russian("Улучшите хранилище Экзопака модулем на 150 слотов. Открой один - и покатились стеллажи на десятки метров!")
			},
			frameType = FrameType.CHALLENGE
		)
		.addCriterion("once4", ExopackSlotsExpandedTrigger.Instance(minGained = 150))
		.save(serializer, modLocation("exopack/once4"), existingFileHelper)
}
