package com.tiedup.remake.client.gui.screens;

import com.tiedup.remake.network.ModNetwork;
import com.tiedup.remake.network.item.PacketAdjustRemote;
import com.tiedup.remake.state.IBondageState;
import com.tiedup.remake.v2.BodyRegionV2;
import java.util.UUID;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * Screen for remotely adjusting Y position of a slave's gags and blindfolds.
 * Similar to AdjustmentScreen but operates on a slave entity.
 *
 */
@OnlyIn(Dist.CLIENT)
public class RemoteAdjustmentScreen extends BaseAdjustmentScreen {

    // Target slave
    private final IBondageState slave;
    private final UUID slaveId;

    public RemoteAdjustmentScreen(IBondageState slave, UUID slaveId) {
        super(Component.translatable("gui.tiedup.adjust_position"));
        this.slave = slave;
        this.slaveId = slaveId;
    }

    // ==================== ABSTRACT IMPLEMENTATIONS ====================

    @Override
    protected LivingEntity getTargetEntity() {
        return slave.asLivingEntity();
    }

    @Override
    protected ItemStack getGag() {
        return slave.getEquipment(BodyRegionV2.MOUTH);
    }

    @Override
    protected ItemStack getBlindfold() {
        return slave.getEquipment(BodyRegionV2.EYES);
    }

    @Override
    protected void sendAdjustment(Mode mode, float value, float scale) {
        BodyRegionV2 region = switch (mode) {
            case GAG -> BodyRegionV2.MOUTH;
            case BLINDFOLD -> BodyRegionV2.EYES;
            case BOTH -> null; // Handled separately in applyAdjustment
        };

        if (region != null) {
            ModNetwork.sendToServer(
                new PacketAdjustRemote(slaveId, region, value, scale)
            );
        }
    }

    @Override
    protected String getExtraInfo() {
        return "Adjusting: " + slave.getKidnappedName();
    }

    @Override
    public void onClose() {
        super.onClose();
    }
}
