package depart.commun.modeles;

import java.util.ArrayList;
import java.util.List;

import ca.ntro.app.models.Model;
import ca.ntro.app.models.WatchJson;
import ca.ntro.app.models.WriteObjectGraph;
import depart.commun.valeurs.ValeurA;
import depart.frontal.vues.VueA;

public class ModeleA implements Model, WatchJson, WriteObjectGraph {

	private boolean attrA = false;
	private double  attrB = 10.0;

	private List<ValeurA> valeurs = new ArrayList<>();
	
	private int attrC = -1;


	public void methodeC(VueA vueA) {

		vueA.methodeA(this.toString());
		
		vueA.methodeF(attrC);
	
		if(attrC <= 0) {
			
			vueA.methodeC();
			vueA.methodeD();
			
		}else if(attrC > 0 && attrC < valeurs.size()-1) {

			vueA.methodeB();
			vueA.methodeC();
			
		}else {

			vueA.methodeB();
			vueA.methodeE();
			
		}

	}
	
	public String toString() {

		StringBuilder builder = new StringBuilder();

		builder.append("attrA: " + attrA);
		builder.append(System.lineSeparator());

		builder.append("attrB: " + attrB);
		builder.append(System.lineSeparator());
		builder.append(System.lineSeparator());

		builder.append("valeur courante: ");
		if(attrC >= 0 && attrC < valeurs.size()) {
			builder.append(valeurs.get(attrC).toString());
		}
		builder.append(System.lineSeparator());
		builder.append(System.lineSeparator());
		
		builder.append("autre valeurs: ");
		builder.append(System.lineSeparator());
		
		int varA = 0;

		for(ValeurA valeur : valeurs) {

			builder.append("  ");
			builder.append(valeur.toString());
			
			if(varA == attrC) {
				builder.append(" <--");
			}

			builder.append(System.lineSeparator());
			
			varA++;

		}

		return builder.toString();
	}

	public void methodeA(String paramA, int paramB) {

		valeurs.add(new ValeurA(paramA, paramB));

	}

	public void methodeB(int paramA) {
		attrC += paramA;
		methodeE();
	}

	public void methodeD(int paramA) {
		attrC = paramA;
		methodeE();
	}

	private void methodeE() {
		if(attrC < 0) {
			attrC = 0;
		}

		else if(attrC >= valeurs.size()) {
			attrC = valeurs.size() - 1;
		}
	}




}
