package xyz.illuc.neuralgiacore.mixin.PrototypePain;

import net.adinvas.prototype_pain.limbs.PlayerHealthData;
import net.minecraft.nbt.CompoundTag;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xyz.illuc.neuralgiacore.interfaces.IPlayerHealthDataAccessor;

@Mixin(PlayerHealthData.class)
public class MixinPlayerHealthDataExtras implements IPlayerHealthDataAccessor {

    // Sepsis
    @Unique
    private float sepsis = 0.0f;

    @Unique
    public float getSepsis() {
        return this.sepsis;
    }

    @Unique
    public void setSepsis(float value) {
        this.sepsis = value;
    }

    // Sickness
    @Unique
    private float sickness = 0.0f;

    @Unique
    public float getSickness() {
        return this.sickness;
    }

    @Unique
    public void setSickness(float value) {
        this.sickness = value;
    }

    // Vomit timer
    @Unique
    private float vomitTime = 0.0f;

    @Override
    public float getVomitTime() {
        return this.vomitTime;
    }

    @Override
    public void setVomitTime(float value) {
        this.vomitTime = value;
    }

    // Blood Vomit timer
    @Unique
    private float bloodVomitTime = 0.0f;

    @Override
    public float getBloodVomitTime() {
        return this.bloodVomitTime;
    }

    @Override
    public void setBloodVomitTime(float value) {
        this.bloodVomitTime = value;
    }

    // Radiation sickness
    @Unique
    private float radiationSickness = 0.0f;

    @Override
    public float getRadiationSickness() {
        return this.radiationSickness;
    }

    @Override
    public void setRadiationSickness(float value) {
        this.radiationSickness = value;
    }

    // Stamina
    @Unique
    private float stamina = 0.0f;

    @Override
    public float getStamina() {
        return this.stamina;
    }

    @Override
    public void setStamina(float value) {
        this.stamina = value;
    }

    @Inject(
            method = "serializeNBT",
            at = @At("RETURN"),
            remap = false
    )
    private void onSerializeNBT(CompoundTag nbt, CallbackInfoReturnable<CompoundTag> cir) {
        CompoundTag tag = cir.getReturnValue();
        tag.putFloat("Sepsis", this.sepsis);
        tag.putFloat("Sickness", this.sickness);
        tag.putFloat("VomitTime", this.vomitTime);
    }

    @Inject(
            method = "deserializeNBT",
            at = @At("TAIL"),
            remap = false
    )
    private void onDeserializeNBT(CompoundTag nbt, CallbackInfo ci) {
        if (nbt.contains("Sepsis")) {
            this.sepsis = nbt.getFloat("Sepsis");
        }
        if (nbt.contains("Sickness")) {
            this.sickness = nbt.getFloat("Sickness");
        }
        if (nbt.contains("VomitTime")) {
            this.vomitTime = nbt.getFloat("VomitTime");
        }
    }

    @Inject(
            method = "resetToDefaults",
            at = @At("TAIL"),
            remap = false
    )
    private void onResetToDefaults(CallbackInfo ci) {
        this.sepsis = 0.0f;
        this.sickness = 0.0f;
        this.vomitTime = 0.0f;
    }

}