package com.tiedup.remake.worldgen;

import com.tiedup.remake.core.TiedUpMod;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.levelgen.structure.StructureType;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

/**
 * Registry for custom structures.
 *
 * Phase: Kidnapper Revamp - Cell System
 */
public class ModStructures {

    // Structure Types
    public static final DeferredRegister<StructureType<?>> STRUCTURE_TYPES =
        DeferredRegister.create(Registries.STRUCTURE_TYPE, TiedUpMod.MOD_ID);

    // Structure Piece Types
    public static final DeferredRegister<
        StructurePieceType
    > STRUCTURE_PIECE_TYPES = DeferredRegister.create(
        Registries.STRUCTURE_PIECE,
        TiedUpMod.MOD_ID
    );

    // === Structure Types ===

    // Kidnapper Camp - Small structure (2 tents)
    public static final RegistryObject<
        StructureType<KidnapperCampStructure>
    > KIDNAPPER_CAMP = STRUCTURE_TYPES.register(
        "kidnapper_camp",
        () -> () -> KidnapperCampStructure.CODEC
    );

    // Kidnapper Outpost - Medium structure (main building + 2-3 cells)
    public static final RegistryObject<
        StructureType<KidnapperOutpostStructure>
    > KIDNAPPER_OUTPOST = STRUCTURE_TYPES.register(
        "kidnapper_outpost",
        () -> () -> KidnapperOutpostStructure.CODEC
    );

    // Kidnapper Fortress - Large structure (keep + 4-6 cells + corridors, with elite)
    public static final RegistryObject<
        StructureType<KidnapperFortressStructure>
    > KIDNAPPER_FORTRESS = STRUCTURE_TYPES.register(
        "kidnapper_fortress",
        () -> () -> KidnapperFortressStructure.CODEC
    );

    // Hanging Cage - Underground cage suspended from cave ceiling
    public static final RegistryObject<
        StructureType<HangingCageStructure>
    > HANGING_CAGE = STRUCTURE_TYPES.register(
        "hanging_cage",
        () -> () -> HangingCageStructure.CODEC
    );

    // === Structure Piece Types ===

    // Shared piece type for all kidnapper structures
    public static final RegistryObject<StructurePieceType> CAMP_PIECE =
        STRUCTURE_PIECE_TYPES.register(
            "camp_piece",
            () ->
                (context, tag) ->
                    new KidnapperCampPiece(
                        context.structureTemplateManager(),
                        tag
                    )
        );

    // Hanging cage piece (programmatic, no NBT template)
    public static final RegistryObject<StructurePieceType> HANGING_CAGE_PIECE =
        STRUCTURE_PIECE_TYPES.register(
            "hanging_cage_piece",
            () -> (context, tag) -> new HangingCagePiece(tag)
        );
}
