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

package com.hypixel.hytale.server.npc.corecomponents.audiovisual.builders;

import com.hypixel.hytale.server.npc.asset.builder.Builder;
import com.hypixel.hytale.server.core.asset.type.soundevent.config.SoundEvent;
import com.hypixel.hytale.server.npc.asset.builder.validators.AssetValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.asset.SoundEventExistsValidator;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.corecomponents.audiovisual.ActionPlaySound;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.holder.AssetHolder;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderActionBase;

public class BuilderActionPlaySound extends BuilderActionBase
{
    protected final AssetHolder soundEventId;
    
    public BuilderActionPlaySound() {
        this.soundEventId = new AssetHolder();
    }
    
    @Nonnull
    @Override
    public ActionPlaySound build(@Nonnull final BuilderSupport builderSupport) {
        return new ActionPlaySound(this, builderSupport);
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Plays a sound to players within a specified range.";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return "Plays a sound to players within a specified range.";
    }
    
    @Nonnull
    @Override
    public BuilderDescriptorState getBuilderDescriptorState() {
        return BuilderDescriptorState.Stable;
    }
    
    @Nonnull
    @Override
    public BuilderActionPlaySound readConfig(@Nonnull final JsonElement data) {
        this.requireAsset(data, "SoundEventId", this.soundEventId, SoundEventExistsValidator.required(), BuilderDescriptorState.Stable, "The sound event to play", null);
        return this;
    }
    
    public String getSoundEventId(@Nonnull final BuilderSupport support) {
        return this.soundEventId.get(support.getExecutionContext());
    }
    
    public int getSoundEventIndex(@Nonnull final BuilderSupport support) {
        final String key = this.soundEventId.get(support.getExecutionContext());
        final int index = SoundEvent.getAssetMap().getIndex(key);
        if (index == Integer.MIN_VALUE) {
            throw new IllegalArgumentException("Unknown key! " + key);
        }
        return index;
    }
}
