package tutorial.rest.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
import java.util.HashMap;
import org.springframework.hateoas.ResourceSupport;
import tutorial.core.models.entities.ActiveIngredientRecomendation;

/**
 * 
 * @author Xavier
 */
public class ActiveIngredientRecomendationResource extends ResourceSupport {

    private String clinicalCare;
    private String adjustDose;
    private String glomerularFiltrationRateRange;
    private int maxGlomerularFiltrationRate;
    private int minGlomerularFiltrationRate;
    private int risk;

    public String getClinicalCare() {
        return clinicalCare;
    }

    public void setClinicalCare(String clinicalCare) {
        this.clinicalCare = clinicalCare;
    }

    public String getAdjustDose() {
        return adjustDose;
    }

    public void setAdjustDose(String adjustDose) {
        this.adjustDose = adjustDose;
    }

    public int getMaxGlomerularFiltrationRate() {
        return maxGlomerularFiltrationRate;
    }

    public String getGlomerularFiltrationRateRange() {
        return glomerularFiltrationRateRange;
    }

    public void setGlomerularFiltrationRateRange(String glomerularFiltrationRateRange) {
        this.glomerularFiltrationRateRange = glomerularFiltrationRateRange;
    }

    
    public void setMaxGlomerularFiltrationRate(int maxGlomerularFiltrationRate) {
        this.maxGlomerularFiltrationRate = maxGlomerularFiltrationRate;
    }

    public int getMinGlomerularFiltrationRate() {
        return minGlomerularFiltrationRate;
    }

    public void setMinGlomerularFiltrationRate(int minGlomerularFiltrationRate) {
        this.minGlomerularFiltrationRate = minGlomerularFiltrationRate;
    }

    public int getRisk() {
        return risk;
    }

    public void setRisk(int risk) {
        this.risk = risk;
    }
    
    public ActiveIngredientRecomendation toActiveIngredientRecomendation() {
        ActiveIngredientRecomendation recomendation = new ActiveIngredientRecomendation();
        recomendation.setClinicalCare(clinicalCare);
        recomendation.setAdjustDose(adjustDose);
        recomendation.setGlomerularFiltrationRateRange(glomerularFiltrationRateRange);
        recomendation.setMaxGlomerularFiltrationRate(maxGlomerularFiltrationRate);
        recomendation.setMinGlomerularFiltrationRate(minGlomerularFiltrationRate);
        recomendation.setRisk(risk);
        return recomendation;
    }
    
    public ActiveIngredientRecomendation setValuesFromHashMap(HashMap<String, Object> values){
        ActiveIngredientRecomendation activeIngredientRecomendation = new ActiveIngredientRecomendation();
        ArrayList<String> names = this.getValuesName();
        //name.get(0) is the ID of the activeIngredient
        String riskStr = (String)values.get(names.get(1));
        activeIngredientRecomendation.setGlomerularFiltrationRateRange((String)values.get(names.get(2)));
        String min = (String)values.get(names.get(3));
        String max = (String)values.get(names.get(4));
        activeIngredientRecomendation.setMinGlomerularFiltrationRate(Integer.parseInt(min));
        activeIngredientRecomendation.setMaxGlomerularFiltrationRate(Integer.parseInt(max));
        activeIngredientRecomendation.setRisk(Integer.parseInt(riskStr));
        activeIngredientRecomendation.setAdjustDose((String)values.get(names.get(5)));
        if(values.size()>6){
            activeIngredientRecomendation.setClinicalCare((String)values.get(names.get(6)));
        }
        return activeIngredientRecomendation;
    }
    
    @JsonIgnore
    public ArrayList<String> getValuesName(){
        ArrayList<String> names = new ArrayList<String>();
        names.add("activeIngredient");
        names.add("risk");
        names.add("glomerularFiltrationRateRange");
        names.add("minGlomerularFiltrationRate");
        names.add("maxGlomerularFiltrationRate");
        names.add("adjustDose");
        names.add("clinicalCare");
        return names;
    }
}
