package com.infinityraider.agricraft.api.v1.stat;

import com.infinityraider.agricraft.api.v1.AgriApi;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;

import javax.annotation.Nonnull;
import java.util.function.Consumer;

public interface IAgriStatsMap {
    int getValue(IAgriStat stat);

    default int getSum() {
        int sum = 0;
        for(IAgriStat stat : AgriApi.getStatRegistry().all()) {
            sum += this.getValue(stat);
        }
        return sum;
    }

    default double getAverage() {
        return (this.getSum() + 0.0) / AgriApi.getStatRegistry().all().size();
    }

    boolean writeToNBT(@Nonnull CompoundNBT tag);

    boolean readFromNBT(@Nonnull CompoundNBT tag);

    default boolean equalStats(IAgriStatsMap other) {
        if(this == other) {
            return true;
        }
        for(IAgriStat stat : AgriApi.getStatRegistry().all()) {
            if(this.getValue(stat) != other.getValue(stat)) {
                return false;
            }
        }
        return true;
    }

    default void addTooltips(@Nonnull Consumer<ITextComponent> consumer) {
        AgriApi.getStatRegistry().stream().forEach(stat -> stat.addTooltip(consumer, this.getValue(stat)));
    }
}

@@ -256,75 +256,449 @@
 r;%0A%0A
-public interface IAgriStatsMap %7B%0A    int getValue(IAgriStat stat);%0A
+/**%0A * Interface representing the AgriCraft stats of a crop or seed, can be retrieved from any IAgriStatProvider.%0A * Examples of IAgriStatProviders are IAgriCrops, AgriSeeds, and IAgriGenomes%0A */%0Apublic interface IAgriStatsMap %7B%0A    /**%0A     * Fetches the value of a certain stat%0A     * @param stat the stat%0A     * @return the value%0A     */%0A    int getValue(IAgriStat stat);%0A%0A    /**%0A     * @return the sum of all values of all stats%0A     */
 %0A   
@@ -875,32 +875,102 @@
 urn sum;%0A    %7D%0A%0A
+    /**%0A     * @return the average of all values of all stats%0A     */%0A
     default doub
@@ -1081,106 +1081,590 @@
     
-boolean writeToNBT(@Nonnull CompoundNBT tag);%0A%0A    boolean readFromNBT(@Nonnull CompoundNBT tag);%0A
+/**%0A     * Serializes the stats map to an NBT tag%0A     * @param tag the tag to write to%0A     * @return true if the serialization was successful%0A     */%0A    boolean writeToNBT(@Nonnull CompoundNBT tag);%0A%0A%0A    /**%0A     * Deserializes the stats map from an NBT tag%0A     * @param tag the tag to read from%0A     * @return true if the deserialization was successful%0A     */%0A    boolean readFromNBT(@Nonnull CompoundNBT tag);%0A%0A    /**%0A     * Checks if the stats are equal%0A     * @param other another stats map%0A     * @return true if all stats contain equal values in both stats maps%0A     */
 %0A   
@@ -1981,24 +1981,131 @@
 rue;%0A    %7D%0A%0A
+    /**%0A     * Adds tooltips for the stats%0A     * @param consumer function to consume the tooltips%0A     */%0A
     default 

Add docs to IAgriStatsMap