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

package com.hypixel.hytale.builtin.hytalegenerator.framework.shaders;

import java.util.Random;
import com.hypixel.hytale.builtin.hytalegenerator.framework.math.SeedGenerator;
import javax.annotation.Nonnull;
import com.hypixel.hytale.builtin.hytalegenerator.datastructures.WeightedMap;

public class WeighedShader<T> implements Shader<T>
{
    @Nonnull
    private final WeightedMap<Shader<T>> childrenWeightedMap;
    private SeedGenerator seedGenerator;
    
    public WeighedShader(@Nonnull final Shader<T> initialChild, final double weight) {
        this.childrenWeightedMap = new WeightedMap<Shader<T>>(1);
        this.seedGenerator = new SeedGenerator(System.nanoTime());
        this.add(initialChild, weight);
    }
    
    @Nonnull
    public WeighedShader<T> add(@Nonnull final Shader<T> child, final double weight) {
        if (weight <= 0.0) {
            throw new IllegalArgumentException("invalid weight");
        }
        this.childrenWeightedMap.add(child, weight);
        return this;
    }
    
    @Nonnull
    public WeighedShader<T> setSeed(final long seed) {
        this.seedGenerator = new SeedGenerator(seed);
        return this;
    }
    
    @Override
    public T shade(final T current, final long seed) {
        final Random r = new Random(seed);
        return this.childrenWeightedMap.pick(r).shade(current, seed);
    }
    
    @Override
    public T shade(final T current, final long seedA, final long seedB) {
        return this.shade(current, this.seedGenerator.seedAt(seedA, seedB));
    }
    
    @Override
    public T shade(final T current, final long seedA, final long seedB, final long seedC) {
        return this.shade(current, this.seedGenerator.seedAt(seedA, seedB, seedC));
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "WeighedShader{childrenWeighedMap=" + String.valueOf(this.childrenWeightedMap) + ", seedGenerator=" + String.valueOf(this.seedGenerator);
    }
}
