package com.tiedup.remake.worldgen;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.structure.StructureType;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;

/**
 * Kidnapper Outpost - Medium-sized structure.
 *
 *
 * Single-piece structure that spawns on flat terrain (like fortress).
 * Uses kidnap_outpost.nbt template.
 *
 * Spawns in plains, forests, and other flat biomes.
 * Structure is lowered by 2 blocks (default Y_OFFSET).
 */
public class KidnapperOutpostStructure extends AbstractKidnapperStructure {

    public static final Codec<KidnapperOutpostStructure> CODEC =
        RecordCodecBuilder.create(instance ->
            instance
                .group(settingsCodec(instance))
                .apply(instance, KidnapperOutpostStructure::new)
        );

    public KidnapperOutpostStructure(StructureSettings settings) {
        super(settings);
    }

    @Override
    protected int getCheckRadius() {
        return 12;
    }

    @Override
    protected int getMaxHeightDifference() {
        return 3;
    }

    @Override
    protected void generatePieces(
        StructurePiecesBuilder builder,
        GenerationContext context,
        BlockPos centerPos,
        Rotation rotation
    ) {
        // Single-piece structure: kidnap_outpost.nbt
        // Y offset of -2 is applied via calculatePiecePosition
        BlockPos outpostPos = calculatePiecePosition(
            context,
            centerPos,
            0,
            0,
            rotation
        );
        builder.addPiece(
            new KidnapperCampPiece(
                context.structureTemplateManager(),
                ResourceLocation.fromNamespaceAndPath(
                    "tiedup",
                    "kidnap_outpost"
                ),
                outpostPos,
                rotation
            )
        );
    }

    @Override
    public StructureType<?> type() {
        return ModStructures.KIDNAPPER_OUTPOST.get();
    }
}
