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

package com.hypixel.hytale.server.core.modules.interaction.commands;

import com.hypixel.hytale.server.core.entity.InteractionChain;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.entity.InteractionContext;
import com.hypixel.hytale.server.core.modules.interaction.InteractionModule;
import com.hypixel.hytale.server.core.entity.InteractionManager;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.RootInteraction;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.protocol.InteractionType;
import com.hypixel.hytale.server.core.command.system.arguments.types.EnumArgumentType;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class InteractionRunSpecificCommand extends AbstractPlayerCommand
{
    @Nonnull
    private static final EnumArgumentType<InteractionType> INTERACTION_TYPE_ARG_TYPE;
    @Nonnull
    private final RequiredArg<InteractionType> interactionTypeArg;
    @Nonnull
    private final RequiredArg<RootInteraction> rootInteractionArg;
    
    public InteractionRunSpecificCommand() {
        super("specific", "server.commands.interaction.runSpecific.desc");
        this.interactionTypeArg = this.withRequiredArg("interactionType", "server.commands.interaction.run.interactionType.desc", InteractionRunSpecificCommand.INTERACTION_TYPE_ARG_TYPE);
        this.rootInteractionArg = this.withRequiredArg("interaction", "server.commands.interaction.runSpecific.rootinteraction.desc", ArgTypes.ROOT_INTERACTION_ASSET);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world) {
        final InteractionManager interactionManager = store.getComponent(ref, InteractionModule.get().getInteractionManagerComponent());
        assert interactionManager != null;
        final InteractionType interactionType = this.interactionTypeArg.get(context);
        final RootInteraction rootInteraction = this.rootInteractionArg.get(context);
        final InteractionContext interactionContext = InteractionContext.forInteraction(interactionManager, ref, interactionType, store);
        final InteractionChain chain = interactionManager.initChain(interactionType, interactionContext, rootInteraction, false);
        interactionManager.queueExecuteChain(chain);
        context.sendMessage(Message.translation("server.commands.interaction.runSpecific.started").param("type", interactionType.name()).param("root", rootInteraction.getId()));
    }
    
    static {
        INTERACTION_TYPE_ARG_TYPE = new EnumArgumentType<InteractionType>("server.commands.parsing.argtype.interactiontype.name", InteractionType.class);
    }
}
