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

package com.hypixel.hytale.server.flock.corecomponents.builders;

import com.hypixel.hytale.server.npc.asset.builder.Builder;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleOrValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.StringNullOrNotEmptyValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.StringValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.StringNotEmptyValidator;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import java.util.Set;
import com.hypixel.hytale.server.flock.corecomponents.ActionFlockBeacon;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.holder.StringHolder;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderActionBase;

public class BuilderActionFlockBeacon extends BuilderActionBase
{
    protected final StringHolder message;
    protected String sendTargetSlot;
    protected double expirationTime;
    protected boolean sendToSelf;
    protected boolean sendToLeaderOnly;
    
    public BuilderActionFlockBeacon() {
        this.message = new StringHolder();
    }
    
    @Nonnull
    @Override
    public ActionFlockBeacon build(@Nonnull final BuilderSupport builderSupport) {
        return new ActionFlockBeacon(this, builderSupport);
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Send beacon message to flock";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return "Let the NPC send out a message to the flock members";
    }
    
    @Override
    public void registerTags(@Nonnull final Set<String> tags) {
        super.registerTags(tags);
        tags.add("message");
    }
    
    @Nonnull
    @Override
    public BuilderDescriptorState getBuilderDescriptorState() {
        return BuilderDescriptorState.Experimental;
    }
    
    @Nonnull
    @Override
    public BuilderActionFlockBeacon readConfig(@Nonnull final JsonElement data) {
        this.requireString(data, "Message", this.message, StringNotEmptyValidator.get(), BuilderDescriptorState.Stable, "Message to send to targets", null);
        this.getString(data, "SendTargetSlot", b -> this.sendTargetSlot = b, null, StringNullOrNotEmptyValidator.get(), BuilderDescriptorState.Stable, "The marked target slot to send. If omitted, sends own position", null);
        this.getDouble(data, "ExpirationTime", d -> this.expirationTime = d, 1.0, DoubleOrValidator.greaterEqual0OrMinus1(), BuilderDescriptorState.Stable, "The number of seconds that the message should last. -1 represents infinite time.", "The number of seconds that the message should last and be acknowledged by the receiving NPC. -1 represents infinite time.");
        this.getBoolean(data, "SendToSelf", b -> this.sendToSelf = b, true, BuilderDescriptorState.Stable, "Send the message to self", null);
        this.getBoolean(data, "SendToLeaderOnly", b -> this.sendToLeaderOnly = b, false, BuilderDescriptorState.Stable, "Only send the message to the leader of the flock", null);
        return this;
    }
    
    public String getMessage(@Nonnull final BuilderSupport builderSupport) {
        return this.message.get(builderSupport.getExecutionContext());
    }
    
    public int getSendTargetSlot(@Nonnull final BuilderSupport support) {
        if (this.sendTargetSlot == null) {
            return Integer.MIN_VALUE;
        }
        return support.getTargetSlot(this.sendTargetSlot);
    }
    
    public double getExpirationTime() {
        return this.expirationTime;
    }
    
    public boolean isSendToSelf() {
        return this.sendToSelf;
    }
    
    public boolean isSendToLeaderOnly() {
        return this.sendToLeaderOnly;
    }
}
