package net.minecraft.world.level.saveddata;

import com.mojang.serialization.Codec;
import java.util.function.Function;
import java.util.function.Supplier;
import net.minecraft.util.datafix.DataFixTypes;

public record SavedDataType<T extends SavedData>(
    String id, Function<SavedData.Context, T> constructor, Function<SavedData.Context, Codec<T>> codec, DataFixTypes dataFixType
) {
    public SavedDataType(String id, Supplier<T> supplier, Codec<T> codec, DataFixTypes dataFixType) {
        this(id, context -> supplier.get(), context -> codec, dataFixType);
    }

    @Override
    public boolean equals(Object other) {
        return other instanceof SavedDataType<?> savedDataType && this.id.equals(savedDataType.id);
    }

    @Override
    public int hashCode() {
        return this.id.hashCode();
    }

    @Override
    public String toString() {
        return "SavedDataType[" + this.id + "]";
    }
}
