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

package com.hypixel.hytale.builtin.adventure.objectives.config;

import com.hypixel.hytale.assetstore.AssetKeyValidator;
import com.hypixel.hytale.codec.schema.metadata.Metadata;
import com.hypixel.hytale.codec.schema.metadata.ui.UIEditor;
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.codec.builder.BuilderCodec;
import java.text.MessageFormat;
import java.util.Arrays;
import javax.annotation.Nullable;
import com.hypixel.hytale.assetstore.AssetRegistry;
import com.hypixel.hytale.assetstore.AssetExtraInfo;
import com.hypixel.hytale.assetstore.AssetStore;
import com.hypixel.hytale.codec.validation.ValidatorCache;
import javax.annotation.Nonnull;
import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec;
import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;

public class ObjectiveLineAsset implements JsonAssetWithMap<String, DefaultAssetMap<String, ObjectiveLineAsset>>
{
    @Nonnull
    public static AssetBuilderCodec<String, ObjectiveLineAsset> CODEC;
    public static final ValidatorCache<String> VALIDATOR_CACHE;
    private static AssetStore<String, ObjectiveLineAsset, DefaultAssetMap<String, ObjectiveLineAsset>> ASSET_STORE;
    protected AssetExtraInfo.Data extraData;
    protected String id;
    protected String category;
    protected String[] objectiveIds;
    protected String objectiveTitleKey;
    protected String objectiveDescriptionKey;
    protected String[] nextObjectiveLineIds;
    
    public static AssetStore<String, ObjectiveLineAsset, DefaultAssetMap<String, ObjectiveLineAsset>> getAssetStore() {
        if (ObjectiveLineAsset.ASSET_STORE == null) {
            ObjectiveLineAsset.ASSET_STORE = AssetRegistry.getAssetStore(ObjectiveLineAsset.class);
        }
        return ObjectiveLineAsset.ASSET_STORE;
    }
    
    public static DefaultAssetMap<String, ObjectiveLineAsset> getAssetMap() {
        return getAssetStore().getAssetMap();
    }
    
    public ObjectiveLineAsset(final String id, final String category, final String[] objectiveIds, final String objectiveTitleKey, final String objectiveDescriptionKey, final String[] nextObjectiveLineIds) {
        this.id = id;
        this.category = category;
        this.objectiveIds = objectiveIds;
        this.objectiveTitleKey = objectiveTitleKey;
        this.objectiveDescriptionKey = objectiveDescriptionKey;
        this.nextObjectiveLineIds = nextObjectiveLineIds;
    }
    
    protected ObjectiveLineAsset() {
    }
    
    @Override
    public String getId() {
        return this.id;
    }
    
    public String getCategory() {
        return this.category;
    }
    
    public String[] getObjectiveIds() {
        return this.objectiveIds;
    }
    
    @Nullable
    public String getNextObjectiveId(final String currentObjectiveId) {
        if (this.objectiveIds == null || this.objectiveIds.length == 0) {
            return null;
        }
        for (int i = 0; i < this.objectiveIds.length - 1; ++i) {
            if (this.objectiveIds[i].equals(currentObjectiveId)) {
                return this.objectiveIds[i + 1];
            }
        }
        return null;
    }
    
    public String getObjectiveTitleKey() {
        return this.objectiveTitleKey;
    }
    
    public String getObjectiveDescriptionKey() {
        return this.objectiveDescriptionKey;
    }
    
    public String[] getNextObjectiveLineIds() {
        return this.nextObjectiveLineIds;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "ObjectiveLineAsset{id='" + this.id + "', category='" + this.category + "', objectiveIds=" + Arrays.toString(this.objectiveIds) + ", objectiveTitleKey='" + this.objectiveTitleKey + "', objectiveDescriptionKey='" + this.objectiveDescriptionKey + "', nextObjectiveLineIds=" + Arrays.toString(this.nextObjectiveLineIds);
    }
    
    static {
        ObjectiveLineAsset.CODEC = ((AssetBuilderCodec.Builder)AssetBuilderCodec.builder(ObjectiveLineAsset.class, ObjectiveLineAsset::new, (Codec<String>)Codec.STRING, (objectiveLine, s) -> objectiveLine.id = s, objectiveLine -> objectiveLine.id, (objectiveLine, data) -> objectiveLine.extraData = data, objectiveLine -> objectiveLine.extraData).appendInherited(new KeyedCodec<String>("Category", Codec.STRING), (objectiveAsset, s) -> objectiveAsset.category = s, objectiveAsset -> objectiveAsset.category, (objectiveAsset, parent) -> objectiveAsset.category = parent.category).add().appendInherited(new KeyedCodec("ObjectiveIds", Codec.STRING_ARRAY), (objectiveLineAsset, strings) -> objectiveLineAsset.objectiveIds = strings, objectiveLineAsset -> objectiveLineAsset.objectiveIds, (objectiveLineAsset, parent) -> objectiveLineAsset.objectiveIds = parent.objectiveIds).addValidator(Validators.nonEmptyArray()).addValidator(Validators.uniqueInArray()).addValidator(ObjectiveAsset.VALIDATOR_CACHE.getArrayValidator()).add().appendInherited(new KeyedCodec("NextObjectiveLineIds", Codec.STRING_ARRAY), (objectiveLineAsset, strings) -> objectiveLineAsset.nextObjectiveLineIds = strings, objectiveLineAsset -> objectiveLineAsset.nextObjectiveLineIds, (objectiveLineAsset, parent) -> objectiveLineAsset.nextObjectiveLineIds = parent.nextObjectiveLineIds).addValidator(Validators.uniqueInArray()).add().appendInherited(new KeyedCodec("TitleId", Codec.STRING), (objectiveLineAsset, s) -> objectiveLineAsset.objectiveTitleKey = s, objectiveLineAsset -> objectiveLineAsset.objectiveTitleKey, (objectiveLineAsset, parent) -> objectiveLineAsset.objectiveTitleKey = parent.objectiveTitleKey).metadata(new UIEditor(new UIEditor.LocalizationKeyField("objectivelines.{assetId}.title", true))).add().appendInherited(new KeyedCodec("DescriptionId", Codec.STRING), (objectiveLineAsset, s) -> objectiveLineAsset.objectiveDescriptionKey = s, objectiveLineAsset -> objectiveLineAsset.objectiveDescriptionKey, (objectiveLineAsset, parent) -> objectiveLineAsset.objectiveDescriptionKey = parent.objectiveDescriptionKey).metadata(new UIEditor(new UIEditor.LocalizationKeyField("objectivelines.{assetId}.desc", true))).add().afterDecode(objectiveAsset -> {
            if (objectiveAsset.objectiveTitleKey != null) {
                objectiveAsset.objectiveTitleKey = MessageFormat.format("objectivelines.{0}.title", objectiveAsset.id);
            }
            if (objectiveAsset.objectiveDescriptionKey != null) {
                objectiveAsset.objectiveDescriptionKey = MessageFormat.format("objectivelines.{0}.desc", objectiveAsset.id);
            }
            return;
        })).build();
        VALIDATOR_CACHE = new ValidatorCache<String>(new AssetKeyValidator<String>(ObjectiveLineAsset::getAssetStore));
    }
}
