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

package com.hypixel.hytale.builtin.adventure.shop;

import com.hypixel.hytale.codec.validation.Validator;
import com.hypixel.hytale.codec.validation.Validators;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.Codec;
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.ui.LocalizableString;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.entity.entities.player.pages.choices.ChoiceElement;

public class ShopElement extends ChoiceElement
{
    public static final BuilderCodec<ShopElement> CODEC;
    protected int cost;
    protected String iconPath;
    
    @Override
    public void addButton(@Nonnull final UICommandBuilder commandBuilder, final UIEventBuilder eventBuilder, final String selector, final PlayerRef playerRef) {
        commandBuilder.append("#ElementList", "Pages/ShopElementButton.ui");
        commandBuilder.set(selector + " #Icon.Background", this.iconPath);
        commandBuilder.setObject(selector + " #Name.Text", (Object)LocalizableString.fromMessageId(this.displayNameKey));
        commandBuilder.setObject(selector + " #Description.Text", (Object)LocalizableString.fromMessageId(this.descriptionKey));
        commandBuilder.set(selector + " #Cost.Text", "" + this.cost);
    }
    
    @Override
    public boolean canFulfillRequirements(@Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef) {
        return super.canFulfillRequirements(store, ref, playerRef);
    }
    
    static {
        CODEC = BuilderCodec.builder(ShopElement.class, ShopElement::new, ChoiceElement.BASE_CODEC).append(new KeyedCodec<Integer>("Cost", Codec.INTEGER), (shopElement, integer) -> shopElement.cost = integer, shopElement -> shopElement.cost).addValidator((Validator<? super Integer>)Validators.greaterThanOrEqual(0)).add().append(new KeyedCodec("Icon", Codec.STRING), (shopElement, s) -> shopElement.iconPath = s, shopElement -> shopElement.iconPath).add().build();
    }
}
