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

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

import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.codecs.map.EnumMapCodec;
import com.hypixel.hytale.codec.Codec;
import java.util.Collections;
import java.util.EnumMap;
import com.hypixel.hytale.component.ComponentType;
import javax.annotation.Nullable;
import com.hypixel.hytale.protocol.InteractionType;
import java.util.Map;
import javax.annotation.Nonnull;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class Interactions implements Component<EntityStore>
{
    @Nonnull
    public static final BuilderCodec<Interactions> CODEC;
    @Nonnull
    private Map<InteractionType, String> interactions;
    @Nullable
    private String interactionHint;
    private boolean isNetworkOutdated;
    
    @Nonnull
    public static ComponentType<EntityStore, Interactions> getComponentType() {
        return InteractionModule.get().getInteractionsComponentType();
    }
    
    public Interactions() {
        this.interactions = new EnumMap<InteractionType, String>(InteractionType.class);
        this.isNetworkOutdated = true;
    }
    
    public Interactions(@Nonnull final Map<InteractionType, String> interactions) {
        this.interactions = new EnumMap<InteractionType, String>(InteractionType.class);
        this.isNetworkOutdated = true;
        this.interactions = new EnumMap<InteractionType, String>(interactions);
    }
    
    @Nullable
    public String getInteractionId(@Nonnull final InteractionType type) {
        return this.interactions.get(type);
    }
    
    public void setInteractionId(@Nonnull final InteractionType type, @Nonnull final String interactionId) {
        this.interactions.put(type, interactionId);
        this.isNetworkOutdated = true;
    }
    
    @Nonnull
    public Map<InteractionType, String> getInteractions() {
        return Collections.unmodifiableMap((Map<? extends InteractionType, ? extends String>)this.interactions);
    }
    
    @Nullable
    public String getInteractionHint() {
        return this.interactionHint;
    }
    
    public void setInteractionHint(@Nullable final String interactionHint) {
        this.interactionHint = interactionHint;
        this.isNetworkOutdated = true;
    }
    
    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        final Interactions clone = new Interactions(this.interactions);
        clone.interactionHint = this.interactionHint;
        return clone;
    }
    
    public boolean consumeNetworkOutdated() {
        final boolean tmp = this.isNetworkOutdated;
        this.isNetworkOutdated = false;
        return tmp;
    }
    
    static {
        CODEC = BuilderCodec.builder(Interactions.class, Interactions::new).appendInherited(new KeyedCodec<Map>("Interactions", (Codec<Map>)new EnumMapCodec((Class<Enum>)InteractionType.class, (Codec<Object>)Codec.STRING, false)), (o, v) -> o.interactions = v, o -> o.interactions, (o, p) -> o.interactions = p.interactions).add().appendInherited(new KeyedCodec("InteractionHint", Codec.STRING), (o, v) -> o.interactionHint = v, o -> o.interactionHint, (o, p) -> o.interactionHint = p.interactionHint).add().build();
    }
}
