package com.example.boidelov3.games.papelito;

/**
 * Représente un joueur du jeu Papelito (Undercover)
 */
public class PapelitoPlayer implements java.io.Serializable {
    private static final long serialVersionUID = 1L;
    private final String name;
    private String secretWord;
    private Role role;
    private boolean isAlive;
    private int votesReceived;

    public enum Role {
        CIVIL("Civil"),
        UNDERCOVER("Undercover"),
        MR_WHITE("Mr. White");

        private final String displayName;

        Role(String displayName) {
            this.displayName = displayName;
        }

        public String getDisplayName() {
            return displayName;
        }
    }

    public PapelitoPlayer(String name) {
        this.name = name;
        this.isAlive = true;
        this.votesReceived = 0;
        this.role = null; // Sera assigné au début du jeu
    }

    public PapelitoPlayer(String name, Role role, String secretWord) {
        this.name = name;
        this.role = role;
        this.secretWord = secretWord;
        this.isAlive = true;
        this.votesReceived = 0;
    }

    public String getName() {
        return name;
    }

    public String getSecretWord() {
        return secretWord;
    }

    public void setSecretWord(String secretWord) {
        this.secretWord = secretWord;
    }

    public Role getRole() {
        return role;
    }
    /**
     * Retourne le rôle du joueur.
     * @return le rôle du joueur, peut être null si non assigné
     */

    public void setRole(Role role) {
        this.role = role;
    }

    public boolean isAlive() {
        return isAlive;
    }

    public void setAlive(boolean alive) {
        isAlive = alive;
    }

    public void eliminate() {
        this.isAlive = false;
    }

    public int getVotesReceived() {
        return votesReceived;
    }

    public void addVote() {
        this.votesReceived++;
    }

    public void resetVotes() {
        this.votesReceived = 0;
    }

    public boolean isMrWhite() {
        return role != null && role == Role.MR_WHITE;
    }

    public boolean isUndercover() {
        return role != null && role == Role.UNDERCOVER;
    }

    public boolean isCivil() {
        return role != null && role == Role.CIVIL;
    }

    @Override
    public String toString() {
        return name + " (" + (role != null ? role.getDisplayName() : "?") + ")";
    }
}
