// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.protocol;

import com.hypixel.hytale.protocol.io.ValidationResult;
import com.hypixel.hytale.protocol.io.ProtocolException;
import com.hypixel.hytale.protocol.io.VarInt;
import io.netty.buffer.ByteBuf;
import java.util.Map;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;

public abstract class Interaction
{
    public static final int MAX_SIZE = 1677721605;
    @Nonnull
    public WaitForDataFrom waitForDataFrom;
    @Nullable
    public InteractionEffects effects;
    public float horizontalSpeedMultiplier;
    public float runTime;
    public boolean cancelOnItemChange;
    @Nullable
    public Map<GameMode, InteractionSettings> settings;
    @Nullable
    public InteractionRules rules;
    @Nullable
    public int[] tags;
    @Nullable
    public InteractionCameraSettings camera;
    
    public Interaction() {
        this.waitForDataFrom = WaitForDataFrom.Client;
    }
    
    @Nonnull
    public static Interaction deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final int typeId = VarInt.peek(buf, offset);
        final int typeIdLen = VarInt.length(buf, offset);
        return switch (typeId) {
            case 0 -> SimpleBlockInteraction.deserialize(buf, offset + typeIdLen);
            case 1 -> SimpleInteraction.deserialize(buf, offset + typeIdLen);
            case 2 -> PlaceBlockInteraction.deserialize(buf, offset + typeIdLen);
            case 3 -> BreakBlockInteraction.deserialize(buf, offset + typeIdLen);
            case 4 -> PickBlockInteraction.deserialize(buf, offset + typeIdLen);
            case 5 -> UseBlockInteraction.deserialize(buf, offset + typeIdLen);
            case 6 -> UseEntityInteraction.deserialize(buf, offset + typeIdLen);
            case 7 -> BuilderToolInteraction.deserialize(buf, offset + typeIdLen);
            case 8 -> ModifyInventoryInteraction.deserialize(buf, offset + typeIdLen);
            case 9 -> ChargingInteraction.deserialize(buf, offset + typeIdLen);
            case 10 -> WieldingInteraction.deserialize(buf, offset + typeIdLen);
            case 11 -> ChainingInteraction.deserialize(buf, offset + typeIdLen);
            case 12 -> ConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 13 -> StatsConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 14 -> BlockConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 15 -> ReplaceInteraction.deserialize(buf, offset + typeIdLen);
            case 16 -> ChangeBlockInteraction.deserialize(buf, offset + typeIdLen);
            case 17 -> ChangeStateInteraction.deserialize(buf, offset + typeIdLen);
            case 18 -> FirstClickInteraction.deserialize(buf, offset + typeIdLen);
            case 20 -> SelectInteraction.deserialize(buf, offset + typeIdLen);
            case 21 -> DamageEntityInteraction.deserialize(buf, offset + typeIdLen);
            case 22 -> RepeatInteraction.deserialize(buf, offset + typeIdLen);
            case 23 -> ParallelInteraction.deserialize(buf, offset + typeIdLen);
            case 24 -> ChangeActiveSlotInteraction.deserialize(buf, offset + typeIdLen);
            case 25 -> EffectConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 26 -> ApplyForceInteraction.deserialize(buf, offset + typeIdLen);
            case 27 -> ApplyEffectInteraction.deserialize(buf, offset + typeIdLen);
            case 28 -> ClearEntityEffectInteraction.deserialize(buf, offset + typeIdLen);
            case 29 -> SerialInteraction.deserialize(buf, offset + typeIdLen);
            case 30 -> ChangeStatInteraction.deserialize(buf, offset + typeIdLen);
            case 31 -> MovementConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 32 -> ProjectileInteraction.deserialize(buf, offset + typeIdLen);
            case 33 -> RemoveEntityInteraction.deserialize(buf, offset + typeIdLen);
            case 34 -> ResetCooldownInteraction.deserialize(buf, offset + typeIdLen);
            case 35 -> TriggerCooldownInteraction.deserialize(buf, offset + typeIdLen);
            case 36 -> CooldownConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 37 -> ChainFlagInteraction.deserialize(buf, offset + typeIdLen);
            case 38 -> IncrementCooldownInteraction.deserialize(buf, offset + typeIdLen);
            case 39 -> CancelChainInteraction.deserialize(buf, offset + typeIdLen);
            case 40 -> RunRootInteraction.deserialize(buf, offset + typeIdLen);
            case 41 -> CameraInteraction.deserialize(buf, offset + typeIdLen);
            case 42 -> SpawnDeployableFromRaycastInteraction.deserialize(buf, offset + typeIdLen);
            case 43 -> MemoriesConditionInteraction.deserialize(buf, offset + typeIdLen);
            case 44 -> ToggleGliderInteraction.deserialize(buf, offset + typeIdLen);
            default -> throw ProtocolException.unknownPolymorphicType("Interaction", typeId);
        };
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        final int typeId = VarInt.peek(buf, offset);
        final int length;
        final int typeIdLen = length = VarInt.length(buf, offset);
        return length + switch (typeId) {
            case 0 -> SimpleBlockInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 1 -> SimpleInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 2 -> PlaceBlockInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 3 -> BreakBlockInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 4 -> PickBlockInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 5 -> UseBlockInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 6 -> UseEntityInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 7 -> BuilderToolInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 8 -> ModifyInventoryInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 9 -> ChargingInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 10 -> WieldingInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 11 -> ChainingInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 12 -> ConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 13 -> StatsConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 14 -> BlockConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 15 -> ReplaceInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 16 -> ChangeBlockInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 17 -> ChangeStateInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 18 -> FirstClickInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 20 -> SelectInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 21 -> DamageEntityInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 22 -> RepeatInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 23 -> ParallelInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 24 -> ChangeActiveSlotInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 25 -> EffectConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 26 -> ApplyForceInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 27 -> ApplyEffectInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 28 -> ClearEntityEffectInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 29 -> SerialInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 30 -> ChangeStatInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 31 -> MovementConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 32 -> ProjectileInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 33 -> RemoveEntityInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 34 -> ResetCooldownInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 35 -> TriggerCooldownInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 36 -> CooldownConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 37 -> ChainFlagInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 38 -> IncrementCooldownInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 39 -> CancelChainInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 40 -> RunRootInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 41 -> CameraInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 42 -> SpawnDeployableFromRaycastInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 43 -> MemoriesConditionInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            case 44 -> ToggleGliderInteraction.computeBytesConsumed(buf, offset + typeIdLen);
            default -> throw ProtocolException.unknownPolymorphicType("Interaction", typeId);
        };
    }
    
    public int getTypeId() {
        if (this instanceof final BreakBlockInteraction sub) {
            return 3;
        }
        if (this instanceof final PickBlockInteraction sub2) {
            return 4;
        }
        if (this instanceof final UseBlockInteraction sub3) {
            return 5;
        }
        if (this instanceof final BlockConditionInteraction sub4) {
            return 14;
        }
        if (this instanceof final ChangeBlockInteraction sub5) {
            return 16;
        }
        if (this instanceof final ChangeStateInteraction sub6) {
            return 17;
        }
        if (this instanceof final SimpleBlockInteraction sub7) {
            return 0;
        }
        if (this instanceof final PlaceBlockInteraction sub8) {
            return 2;
        }
        if (this instanceof final UseEntityInteraction sub9) {
            return 6;
        }
        if (this instanceof final BuilderToolInteraction sub10) {
            return 7;
        }
        if (this instanceof final ModifyInventoryInteraction sub11) {
            return 8;
        }
        if (this instanceof final WieldingInteraction sub12) {
            return 10;
        }
        if (this instanceof final ConditionInteraction sub13) {
            return 12;
        }
        if (this instanceof final StatsConditionInteraction sub14) {
            return 13;
        }
        if (this instanceof final SelectInteraction sub15) {
            return 20;
        }
        if (this instanceof final RepeatInteraction sub16) {
            return 22;
        }
        if (this instanceof final EffectConditionInteraction sub17) {
            return 25;
        }
        if (this instanceof final ApplyForceInteraction sub18) {
            return 26;
        }
        if (this instanceof final ApplyEffectInteraction sub19) {
            return 27;
        }
        if (this instanceof final ClearEntityEffectInteraction sub20) {
            return 28;
        }
        if (this instanceof final ChangeStatInteraction sub21) {
            return 30;
        }
        if (this instanceof final MovementConditionInteraction sub22) {
            return 31;
        }
        if (this instanceof final ProjectileInteraction sub23) {
            return 32;
        }
        if (this instanceof final RemoveEntityInteraction sub24) {
            return 33;
        }
        if (this instanceof final ResetCooldownInteraction sub25) {
            return 34;
        }
        if (this instanceof final TriggerCooldownInteraction sub26) {
            return 35;
        }
        if (this instanceof final CooldownConditionInteraction sub27) {
            return 36;
        }
        if (this instanceof final ChainFlagInteraction sub28) {
            return 37;
        }
        if (this instanceof final IncrementCooldownInteraction sub29) {
            return 38;
        }
        if (this instanceof final CancelChainInteraction sub30) {
            return 39;
        }
        if (this instanceof final RunRootInteraction sub31) {
            return 40;
        }
        if (this instanceof final CameraInteraction sub32) {
            return 41;
        }
        if (this instanceof final SpawnDeployableFromRaycastInteraction sub33) {
            return 42;
        }
        if (this instanceof final ToggleGliderInteraction sub34) {
            return 44;
        }
        if (this instanceof final SimpleInteraction sub35) {
            return 1;
        }
        if (this instanceof final ChargingInteraction sub36) {
            return 9;
        }
        if (this instanceof final ChainingInteraction sub37) {
            return 11;
        }
        if (this instanceof final ReplaceInteraction sub38) {
            return 15;
        }
        if (this instanceof final FirstClickInteraction sub39) {
            return 18;
        }
        if (this instanceof final DamageEntityInteraction sub40) {
            return 21;
        }
        if (this instanceof final ParallelInteraction sub41) {
            return 23;
        }
        if (this instanceof final ChangeActiveSlotInteraction sub42) {
            return 24;
        }
        if (this instanceof final SerialInteraction sub43) {
            return 29;
        }
        if (this instanceof final MemoriesConditionInteraction sub44) {
            return 43;
        }
        throw new IllegalStateException("Unknown subtype: " + this.getClass().getName());
    }
    
    public abstract int serialize(@Nonnull final ByteBuf p0);
    
    public abstract int computeSize();
    
    public int serializeWithTypeId(@Nonnull final ByteBuf buf) {
        final int startPos = buf.writerIndex();
        VarInt.write(buf, this.getTypeId());
        this.serialize(buf);
        return buf.writerIndex() - startPos;
    }
    
    public int computeSizeWithTypeId() {
        return VarInt.size(this.getTypeId()) + this.computeSize();
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        final int typeId = VarInt.peek(buffer, offset);
        final int typeIdLen = VarInt.length(buffer, offset);
        return switch (typeId) {
            case 0 -> SimpleBlockInteraction.validateStructure(buffer, offset + typeIdLen);
            case 1 -> SimpleInteraction.validateStructure(buffer, offset + typeIdLen);
            case 2 -> PlaceBlockInteraction.validateStructure(buffer, offset + typeIdLen);
            case 3 -> BreakBlockInteraction.validateStructure(buffer, offset + typeIdLen);
            case 4 -> PickBlockInteraction.validateStructure(buffer, offset + typeIdLen);
            case 5 -> UseBlockInteraction.validateStructure(buffer, offset + typeIdLen);
            case 6 -> UseEntityInteraction.validateStructure(buffer, offset + typeIdLen);
            case 7 -> BuilderToolInteraction.validateStructure(buffer, offset + typeIdLen);
            case 8 -> ModifyInventoryInteraction.validateStructure(buffer, offset + typeIdLen);
            case 9 -> ChargingInteraction.validateStructure(buffer, offset + typeIdLen);
            case 10 -> WieldingInteraction.validateStructure(buffer, offset + typeIdLen);
            case 11 -> ChainingInteraction.validateStructure(buffer, offset + typeIdLen);
            case 12 -> ConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 13 -> StatsConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 14 -> BlockConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 15 -> ReplaceInteraction.validateStructure(buffer, offset + typeIdLen);
            case 16 -> ChangeBlockInteraction.validateStructure(buffer, offset + typeIdLen);
            case 17 -> ChangeStateInteraction.validateStructure(buffer, offset + typeIdLen);
            case 18 -> FirstClickInteraction.validateStructure(buffer, offset + typeIdLen);
            case 20 -> SelectInteraction.validateStructure(buffer, offset + typeIdLen);
            case 21 -> DamageEntityInteraction.validateStructure(buffer, offset + typeIdLen);
            case 22 -> RepeatInteraction.validateStructure(buffer, offset + typeIdLen);
            case 23 -> ParallelInteraction.validateStructure(buffer, offset + typeIdLen);
            case 24 -> ChangeActiveSlotInteraction.validateStructure(buffer, offset + typeIdLen);
            case 25 -> EffectConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 26 -> ApplyForceInteraction.validateStructure(buffer, offset + typeIdLen);
            case 27 -> ApplyEffectInteraction.validateStructure(buffer, offset + typeIdLen);
            case 28 -> ClearEntityEffectInteraction.validateStructure(buffer, offset + typeIdLen);
            case 29 -> SerialInteraction.validateStructure(buffer, offset + typeIdLen);
            case 30 -> ChangeStatInteraction.validateStructure(buffer, offset + typeIdLen);
            case 31 -> MovementConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 32 -> ProjectileInteraction.validateStructure(buffer, offset + typeIdLen);
            case 33 -> RemoveEntityInteraction.validateStructure(buffer, offset + typeIdLen);
            case 34 -> ResetCooldownInteraction.validateStructure(buffer, offset + typeIdLen);
            case 35 -> TriggerCooldownInteraction.validateStructure(buffer, offset + typeIdLen);
            case 36 -> CooldownConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 37 -> ChainFlagInteraction.validateStructure(buffer, offset + typeIdLen);
            case 38 -> IncrementCooldownInteraction.validateStructure(buffer, offset + typeIdLen);
            case 39 -> CancelChainInteraction.validateStructure(buffer, offset + typeIdLen);
            case 40 -> RunRootInteraction.validateStructure(buffer, offset + typeIdLen);
            case 41 -> CameraInteraction.validateStructure(buffer, offset + typeIdLen);
            case 42 -> SpawnDeployableFromRaycastInteraction.validateStructure(buffer, offset + typeIdLen);
            case 43 -> MemoriesConditionInteraction.validateStructure(buffer, offset + typeIdLen);
            case 44 -> ToggleGliderInteraction.validateStructure(buffer, offset + typeIdLen);
            default -> ValidationResult.error("Unknown polymorphic type ID " + typeId + " for Interaction");
        };
    }
}
