package net.minecraft.world.entity.npc;

import com.mojang.datafixers.kinds.Applicative;
import net.minecraft.core.Registry;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.mojang.serialization.Codec;

public class VillagerData {
    private static final int[] NEXT_LEVEL_XP_THRESHOLDS;
    public static final Codec<VillagerData> CODEC;
    private final VillagerType type;
    private final VillagerProfession profession;
    private final int level;
    
    public VillagerData(final VillagerType bdu, final VillagerProfession bds, final int integer) {
        this.type = bdu;
        this.profession = bds;
        this.level = Math.max(1, integer);
    }
    
    public VillagerType getType() {
        return this.type;
    }
    
    public VillagerProfession getProfession() {
        return this.profession;
    }
    
    public int getLevel() {
        return this.level;
    }
    
    public VillagerData setType(final VillagerType bdu) {
        return new VillagerData(bdu, this.profession, this.level);
    }
    
    public VillagerData setProfession(final VillagerProfession bds) {
        return new VillagerData(this.type, bds, this.level);
    }
    
    public VillagerData setLevel(final int integer) {
        return new VillagerData(this.type, this.profession, integer);
    }
    
    public static int getMinXpPerLevel(final int integer) {
        return canLevelUp(integer) ? VillagerData.NEXT_LEVEL_XP_THRESHOLDS[integer - 1] : 0;
    }
    
    public static int getMaxXpPerLevel(final int integer) {
        return canLevelUp(integer) ? VillagerData.NEXT_LEVEL_XP_THRESHOLDS[integer] : 0;
    }
    
    public static boolean canLevelUp(final int integer) {
        return integer >= 1 && integer < 5;
    }
    
    static {
        NEXT_LEVEL_XP_THRESHOLDS = new int[] { 0, 10, 70, 150, 250 };
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Registry.VILLAGER_TYPE.fieldOf("type").withDefault(() -> VillagerType.PLAINS).forGetter(bdq -> bdq.type), (App)Registry.VILLAGER_PROFESSION.fieldOf("profession").withDefault(() -> VillagerProfession.NONE).forGetter(bdq -> bdq.profession), (App)Codec.INT.fieldOf("level").withDefault(1).forGetter(bdq -> bdq.level)).apply(instance, VillagerData::new));
    }
}
