package com.tiedup.remake.entities;

import com.tiedup.remake.core.TiedUpMod;
import com.tiedup.remake.v2.furniture.EntityFurniture;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

/**
 *
 * Registry for custom entities added by the TiedUp mod.
 *
 * Current Entities:
 * - EntityDamsel: Capturable female NPC with bondage support
 * - EntityKidnapper: Aggressive NPC that captures and enslaves players
 * - EntityKidnapperElite: Rare, faster kidnapper variant
 * - LeashProxyEntity: Invisible turtle for player leashing (via mixin)
 *
 * Future Entities:
 * - EntityBondageFurniture: Furniture for bondage scenes
 *
 * @see EntityDamsel
 * @see EntityKidnapper
 * @see EntityKidnapperElite
 * @see LeashProxyEntity
 */
@SuppressWarnings("null") // Minecraft API guarantees non-null returns
public class ModEntities {

    /**
     * Deferred register for entity types.
     */
    public static final DeferredRegister<EntityType<?>> ENTITIES =
        DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, TiedUpMod.MOD_ID);

    /**
     * Damsel Entity
     *
     *
     * Purpose:
     * - Capturable female NPCs that can be restrained and enslaved
     * - Full IRestrainable implementation (binds, gags, collars, etc.)
     * - 38 skin variants (18 classic + 20 guest)
     * - Conditional AI (flees when free, wanders when not tied, etc.)
     *
     * Technical Details:
     * - Type: PathfinderMob
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks (high visibility)
     * - Update Interval: 3 ticks (default)
     * - Sends Velocity Updates: true
     *
     * Registry Name: "damsel"
     */
    public static final RegistryObject<EntityType<EntityDamsel>> DAMSEL =
        ENTITIES.register("damsel", () ->
            EntityType.Builder.of(EntityDamsel::new, MobCategory.CREATURE)
                .sized(0.6F, 1.8F) // Player size
                .clientTrackingRange(80) // Track from far away
                .updateInterval(3)
                .setShouldReceiveVelocityUpdates(true)
                .build("damsel")
        );

    /**
     * Shiny Damsel Entity
     *
     *
     * Purpose:
     * - Rare variant of regular Damsel
     * - Much faster movement speed (0.35 vs 0.25)
     * - Golden sparkle particles
     * - Shiny-exclusive skins
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityDamsel)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Movement speed: 0.35 (vs 0.25 for regular)
     *
     * Registry Name: "damsel_shiny"
     */
    public static final RegistryObject<
        EntityType<EntityDamselShiny>
    > DAMSEL_SHINY = ENTITIES.register("damsel_shiny", () ->
        EntityType.Builder.of(EntityDamselShiny::new, MobCategory.CREATURE)
            .sized(0.6F, 1.8F) // Player size
            .clientTrackingRange(80)
            .updateInterval(3)
            .setShouldReceiveVelocityUpdates(true)
            .build("damsel_shiny")
    );

    /**
     * Kidnapper Entity
     *
     *
     * Purpose:
     * - Hunts and captures players
     * - Implements ICaptor for slave management
     * - Can tie up, gag, and enslave players
     * - Brings slaves to prison location
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityDamsel)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Faster movement speed than damsel
     *
     * Registry Name: "kidnapper"
     */
    public static final RegistryObject<EntityType<EntityKidnapper>> KIDNAPPER =
        ENTITIES.register("kidnapper", () ->
            EntityType.Builder.of(EntityKidnapper::new, MobCategory.CREATURE)
                .sized(0.6F, 1.8F) // Player size
                .clientTrackingRange(80)
                .updateInterval(3)
                .setShouldReceiveVelocityUpdates(true)
                .build("kidnapper")
        );

    /**
     * Elite Kidnapper Entity
     *
     *
     * Purpose:
     * - Rare spawn (elite version of kidnapper)
     * - Faster movement and capture time
     * - Higher health and knockback resistance
     * - Unique skins (Suki, Carol, Athena, Evelyn)
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityKidnapper)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Movement speed: 0.30 (vs 0.27 for regular)
     * - Capture time: 10 ticks (vs 20 for regular)
     *
     * Registry Name: "kidnapper_elite"
     */
    public static final RegistryObject<
        EntityType<EntityKidnapperElite>
    > KIDNAPPER_ELITE = ENTITIES.register("kidnapper_elite", () ->
        EntityType.Builder.of(EntityKidnapperElite::new, MobCategory.CREATURE)
            .sized(0.6F, 1.8F) // Player size
            .clientTrackingRange(80)
            .updateInterval(3)
            .setShouldReceiveVelocityUpdates(true)
            .build("kidnapper_elite")
    );

    /**
     * Merchant Kidnapper Entity
     *
     * Elite kidnapper who trades mod items for gold.
     *
     * Purpose:
     * - Neutral merchant selling mod items for gold ingots/nuggets
     * - Becomes hostile elite kidnapper when attacked
     * - Reverts to merchant after 5 minutes or when attacker captured/sold
     *
     * Trading:
     * - Sells 8-12 random mod items
     * - Tier-based pricing (1-2 gold for basic, 10-20 for GPS collar)
     * - Fixed trades (persist in NBT)
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityKidnapperElite)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Same stats as Elite (40 HP, 0.35 speed)
     *
     * Registry Name: "kidnapper_merchant"
     */
    public static final RegistryObject<
        EntityType<EntityKidnapperMerchant>
    > KIDNAPPER_MERCHANT = ENTITIES.register("kidnapper_merchant", () ->
        EntityType.Builder.of(
            EntityKidnapperMerchant::new,
            MobCategory.CREATURE
        )
            .sized(0.6F, 1.8F) // Player size
            .clientTrackingRange(80)
            .updateInterval(3)
            .setShouldReceiveVelocityUpdates(true)
            .build("kidnapper_merchant")
    );

    /**
     * Archer Kidnapper Entity
     *
     *
     * Purpose:
     * - Attacks from range with rope arrows
     * - Ties up targets before approaching
     * - Lower health but faster movement
     * - Unique archer skins
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityKidnapper)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Attack range: 10-25 blocks
     *
     * Registry Name: "kidnapper_archer"
     */
    public static final RegistryObject<
        EntityType<EntityKidnapperArcher>
    > KIDNAPPER_ARCHER = ENTITIES.register("kidnapper_archer", () ->
        EntityType.Builder.of(EntityKidnapperArcher::new, MobCategory.CREATURE)
            .sized(0.6F, 1.8F) // Player size
            .clientTrackingRange(80)
            .updateInterval(3)
            .setShouldReceiveVelocityUpdates(true)
            .build("kidnapper_archer")
    );

    /**
     * Rope Arrow Entity
     *
     *
     * Purpose:
     * - Ranged restraint tool
     * - 75% chance to bind target on hit
     * - Works on Players, Damsels, Kidnappers
     *
     * Technical Details:
     * - Type: AbstractArrow
     * - Category: MISC (projectile)
     * - Size: 0.5F x 0.5F (same as arrow)
     * - Tracking Range: 4 blocks
     *
     * Registry Name: "rope_arrow"
     */
    public static final RegistryObject<EntityType<EntityRopeArrow>> ROPE_ARROW =
        ENTITIES.register("rope_arrow", () ->
            EntityType.Builder.<EntityRopeArrow>of(
                EntityRopeArrow::new,
                MobCategory.MISC
            )
                .sized(0.5F, 0.5F)
                .clientTrackingRange(4)
                .updateInterval(20)
                .build("rope_arrow")
        );

    /**
     * Kidnap Bomb Entity
     *
     *
     * Purpose:
     * - TNT that applies bondage instead of destruction
     * - Stores bondage items to apply on explosion
     * - Uses KidnapExplosion for area effect
     *
     * Technical Details:
     * - Type: PrimedTnt (extends)
     * - Category: MISC (projectile-like)
     * - Size: 0.98F x 0.98F (same as TNT)
     * - Tracking Range: 10 blocks
     *
     * Registry Name: "kidnap_bomb_entity"
     */
    public static final RegistryObject<
        EntityType<EntityKidnapBomb>
    > KIDNAP_BOMB_ENTITY = ENTITIES.register("kidnap_bomb_entity", () ->
        EntityType.Builder.<EntityKidnapBomb>of(
            EntityKidnapBomb::new,
            MobCategory.MISC
        )
            .sized(0.98F, 0.98F)
            .clientTrackingRange(10)
            .updateInterval(10)
            .fireImmune()
            .build("kidnap_bomb_entity")
    );

    /**
     * Slave Trader Entity
     *
     * Slave Trader & Maid System - Boss of a camp who sells captives.
     *
     * Purpose:
     * - Manages sale of captives in camp cells
     * - Does not capture (stays at camp)
     * - Has a Maid servant
     * - Token required for peaceful interaction
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityKidnapperElite)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - High stats (50 HP, 0.30 speed)
     *
     * Registry Name: "slave_trader"
     */
    public static final RegistryObject<
        EntityType<EntitySlaveTrader>
    > SLAVE_TRADER = ENTITIES.register("slave_trader", () ->
        EntityType.Builder.of(EntitySlaveTrader::new, MobCategory.CREATURE)
            .sized(0.6F, 1.8F)
            .clientTrackingRange(80)
            .updateInterval(3)
            .setShouldReceiveVelocityUpdates(true)
            .build("slave_trader")
    );

    /**
     * Maid Entity
     *
     * Slave Trader & Maid System - Servant who executes trader's orders.
     *
     * Purpose:
     * - Follows and protects the SlaveTrader
     * - Delivers captives to buyers
     * - Collects ransom/items
     * - Highest stats in mod (ultra fast capture)
     * - Becomes neutral when trader dies
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityKidnapperElite)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Highest stats (60 HP, 0.40 speed, 5 tick capture)
     *
     * Registry Name: "maid"
     */
    public static final RegistryObject<EntityType<EntityMaid>> MAID =
        ENTITIES.register("maid", () ->
            EntityType.Builder.of(EntityMaid::new, MobCategory.CREATURE)
                .sized(0.6F, 1.8F)
                .clientTrackingRange(80)
                .updateInterval(3)
                .setShouldReceiveVelocityUpdates(true)
                .build("maid")
        );

    /**
     * Master Entity
     *
     * Master NPC - Rare NPC that buys solo players from Kidnappers.
     *
     * Purpose:
     * - Spawns when a Kidnapper sells a player in solo mode
     * - Implements pet play mechanics (collar, bowl, pet bed)
     * - Follows the player (inverted follower mechanic)
     * - Restricts eating/sleeping to special blocks
     * - Monitors and punishes escape attempts
     * - Very high combat stats (hard to defeat)
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityKidnapperElite)
     * - Category: CREATURE (spawnable NPC)
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Ultra-tank stats (150 HP, armor, regen)
     *
     * Registry Name: "master"
     */
    public static final RegistryObject<EntityType<EntityMaster>> MASTER =
        ENTITIES.register("master", () ->
            EntityType.Builder.of(EntityMaster::new, MobCategory.CREATURE)
                .sized(0.6F, 1.8F)
                .clientTrackingRange(80)
                .updateInterval(3)
                .setShouldReceiveVelocityUpdates(true)
                .build("master")
        );

    /**
     * Labor Guard Entity
     *
     * Physical guard that follows and monitors a prisoner during labor.
     *
     * Purpose:
     * - Follows prisoner during forced labor
     * - Monitors activity and punishes inactivity
     * - Protects prisoner from monsters
     * - Triggers escape if prisoner leaves zone or guard dies
     *
     * Technical Details:
     * - Type: PathfinderMob (extends EntityDamsel)
     * - Category: CREATURE
     * - Size: 0.6F x 1.8F (same as player)
     * - Tracking Range: 80 blocks
     * - Stats: 30 HP, 0.30 speed, 6.0 attack
     *
     * Registry Name: "labor_guard"
     */
    public static final RegistryObject<
        EntityType<EntityLaborGuard>
    > LABOR_GUARD = ENTITIES.register("labor_guard", () ->
        EntityType.Builder.of(EntityLaborGuard::new, MobCategory.CREATURE)
            .sized(0.6F, 1.8F)
            .clientTrackingRange(80)
            .updateInterval(3)
            .setShouldReceiveVelocityUpdates(true)
            .build("labor_guard")
    );

    /**
     * NPC Fishing Bobber Entity
     *
     * Lightweight bobber spawned by NPC during fishing job.
     * Floats on water, triggers bite after random delay.
     * Ephemeral (no NBT persistence).
     *
     * Registry Name: "npc_fishing_bobber"
     */
    public static final RegistryObject<
        EntityType<NpcFishingBobber>
    > NPC_FISHING_BOBBER = ENTITIES.register("npc_fishing_bobber", () ->
        EntityType.Builder.<NpcFishingBobber>of(
            NpcFishingBobber::new,
            MobCategory.MISC
        )
            .sized(0.25F, 0.25F)
            .clientTrackingRange(64)
            .updateInterval(5)
            .build("npc_fishing_bobber")
    );

    /**
     * Furniture Entity
     *
     * Data-driven furniture piece with configurable seats, locking, and models.
     *
     * Purpose:
     * - Spawnable furniture whose behavior is defined by FurnitureRegistry JSON
     * - Supports seating, locking, and breaking mechanics via FurnitureDefinition
     * - Uses IEntityAdditionalSpawnData for client sync of furniture ID
     *
     * Technical Details:
     * - Type: Entity (NOT LivingEntity — no attributes needed)
     * - Category: MISC (placed object, not spawnable mob)
     * - Size: 3.0F x 3.0F (generous default; actual hitbox comes from FurnitureDefinition)
     * - Tracking Range: 64 blocks
     * - Update Interval: 20 ticks (low frequency — furniture is stationary)
     * - No velocity updates (stationary entity)
     *
     * Registry Name: "furniture"
     */
    public static final RegistryObject<EntityType<EntityFurniture>> FURNITURE =
        ENTITIES.register("furniture", () ->
            EntityType.Builder.<EntityFurniture>of(
                EntityFurniture::new,
                MobCategory.MISC
            )
                .sized(3.0F, 3.0F)
                .clientTrackingRange(64)
                .updateInterval(20)
                .setShouldReceiveVelocityUpdates(false)
                .build("furniture")
        );
}
