package rip.tilly.bedwars.playerdata;

import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.managers.PlayerDataManager;
import rip.tilly.bedwars.utils.CC;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

@Getter
@Setter
public class PlayerData {

    private final PlayerDataManager playerDataManager = BedWars.getInstance().getPlayerDataManager();
    private PlayerState playerState = PlayerState.SPAWN;

    private PlayerSettings playerSettings = new PlayerSettings();

    private PlayerTeam playerTeam;

    private final UUID uniqueId;
    private boolean loaded;

    private UUID currentGameId;
    private int teamId;

    private int kills;
    private int deaths;
    private double xp;
    private int level;
    private int wins;
    private int losses;
    private int gamesPlayed;
    private int bedsDestroyed;

    private Player lastDamager;
    private int gameKills;
    private int gameBedsDestroyed;

    public PlayerData(UUID uniqueId) {
        this.uniqueId = uniqueId;
        this.loaded = false;

        this.playerDataManager.loadPlayerData(this);
    }

    public void addRandomXp(Player player) {
        double xp = ThreadLocalRandom.current().nextDouble(0.01, 0.05);

        this.xp += xp;

        player.sendMessage(CC.translate("&b&l+" + ((int) (xp * 100)) + "&b&l% xp"));

        if (this.xp >= 1) {
            this.level += 1;
            this.xp = this.xp - (long) this.xp;
        }
    }
}
