package POO.Clase2;

import java.util.Random;

public class Persona {
    //static == Variable de clase
    public final static int SOBREPESO= 1;
    public final static int PESO_MEDIO= 0;
    public final static int BAJO_PESO= -1;
    
    //ATRIBUTOS

    //- Únicamente se declaran, no se inicializan.
    //- **ENCAPSULACIÓN** 
    private String nombre;
    private int edad;
    private String DNI;
    private char sexo;
    private double peso;
    private double altura;

    //Modificadores de acceso [public, private, protected]
    //CONSTRUCTORES
    //¿Qué significa constructor por defecto?
    //Es el constructor vacío.
    public Persona() {
        this.nombre = "";
        this.edad = 0;
        this.DNI = "00000000A";
        this.sexo = 'H';
        this.peso = 0;
        this.altura = 0;
        //char = ' ' | String = " DE ACUERDO PERO TENGO QUE PONER TODOS LOS ATRIBUTOS?" 
    }

    //Un constructor con el nombre, edad y sexo, el resto por defecto
    public Persona(String nombre, int edad, char sexo) {
        this.nombre = nombre;
        this.edad = edad;
        this.sexo = sexo;
        this.peso = 0;
        this.altura = 0;
        this.DNI = "00000000A";
    }

    // PARAMETRO
    public Persona(String nombre, int edad, char sexo, double peso, double altura, String DNI) {
        this.nombre = nombre;
        this.edad = edad;
        this.sexo = sexo;
        this.peso = peso;
        this.altura = altura;
        this.DNI = DNI;
    }

    //Un constructor con todos los atributos como parámetro.
    //GETTERS
    //SETTERS
    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public void setEdad(int edad) {
        this.edad = edad;
    }

    public void setSexo(char sexo) {
        this.sexo = sexo;
    }

    public void setPeso(double peso) {
        this.peso = peso;
    }

    public void setAltura(double altura) {
        this.altura = altura;
    }

    //TOSTRING 
    //MÉTODOS PERSONALIZADOS
    public boolean esMayorDeEdad() {
        return edad>=18;
        
        /*if (edad > 18) {
            return true;
        } else {
            return false;
        }*/
    }
    
    public char comprobarSexo(char sexo)
    {
        //Controla que el sexo introducido sea o M (Mujer) o H (Hombre), y si es diferente por ejemplo 'L',me devuelve H (Por defecto).
        if (sexo == 'H' | sexo == 'M')
        { //Si doy un sexo correcto, devuelvo dicho sexo. 
            return sexo;
        }
        else
        {
            return 'H';
        } 
    }
    
    public void generaDNI()
    {
        //1º Crear un String vacio.
        //2º Generar 1 a 1 8 dígitos (aleatorios)
        //3º En base a los digitos asignar la letra.
        String DNI = "";
        char[] letra = {'T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'};
        
        //Rellenamos los dígitos
        Random rd = new Random();
        for (int i = 0; i < 8; i++) {
            int numeroGenerado = rd.nextInt(9);
            DNI+=numeroGenerado;  
        }
        //Para poder obtener el módulo del DNI (Resto de la división), que sea un numérico.
        int digitos = Integer.parseInt(DNI);
        DNI+=letra[digitos%23];
        
        this.DNI =  DNI;
        
        
        
    }
    
    public int calcularIMC()
    {
        double indice = peso/(altura*altura);
        if (indice < 20)
        {
            return BAJO_PESO;
        }
        //{20,25} {20,21,22,23,24,25}
        else if (indice >= 20 && indice <= 25)
        {
            return PESO_MEDIO;
        }
        else //if (indice > 25)
        {
            return SOBREPESO;
        }
    }
    //GETTERS
    /*
        private String nombre;
    private int edad;
    private String DNI;
    private char sexo;
    private double peso;
    private double altura;
    */
    public String getNombre(){
        return this.nombre;
    }
    public int getEdad()
    {
        return this.edad;
    }
    public String getDNI()
    {
        return this.DNI;
    }
    public char getSexo()
    {
        return this.sexo;
    }
    public double getPeso()
    {
        return this.peso;
    }
    public double getAltura()
    {
        return this.altura;
    }
    
    //Dice en que categoría de edad entre
    //NIÑO[0-17], JOVEN[18-29], ADULTO[30-54], MAYOR[55-100]
    public String CategoriaEdad()
    {
        if (edad >= 0 && edad <=17 ){
            return "NIÑO";
        }else if (edad > 18 && edad<=29){
            return "JOVEN";
        }else if (edad >=30 && edad<=54){
            return "ADULTO";
        }else{
            return "MAYOR";
        }
        
    }
    
    @Override
    public String toString()
    {
        return "Nombre " + this.nombre + " \nEdad " + this.edad + "\nDNI " + this.DNI + "\nSexo " + this.sexo + "\nPeso " + this.peso + "\nAltura " + this.altura;
    }
    
}
