package depart.frontal.taches;

import depart.frontal.donnees.DonneesVueB;
import depart.frontal.evenements.EvtAgrandirMonde2d;
import depart.frontal.vues.VueB;

import static ca.ntro.app.tasks.frontend.FrontendTasks.*;

import ca.ntro.app.tasks.frontend.FrontendTasks;


public class TachesE {
	
	public static void creerTaches(FrontendTasks tasks) {
		
		creerDonneesVueB(tasks);

		tasks.taskGroup("TachesE")
		
		     .waitsFor(created(DonneesVueB.class))

		     .contains(subTasks -> {
		    	 
		    	 tacheE2(subTasks);
		    	 
		    	 agrandirMonde2d(subTasks);

		     });
	}

	private static void creerDonneesVueB(FrontendTasks tasks) {

		tasks.task(create(DonneesVueB.class))

		     .waitsFor("tacheC2")

			 .waitsFor(created(VueB.class))
		     
		     .executesAndReturnsValue(inputs -> {

		    	 var objA = inputs.get(created(VueB.class));

		    	 var objB = new DonneesVueB();
		    	 
		    	 objB.methodeD(objA);
		    	 

		    	 

		    	 return objB;

		     });
	}

	private static void tacheE2(FrontendTasks tasks) {
		
		tasks.task("tacheE2")

		     .waitsFor("tacheC2")

			 .waitsFor(created(DonneesVueB.class))
			 
			 .waitsFor(created(VueB.class))

			 .waitsFor(clock().nextTick())

		     .executes(inputs -> {
		    	 
		    	 var objA = inputs.get(created(VueB.class));
		    	 var objB = inputs.get(created(DonneesVueB.class));
		    	 var objC = inputs.get(clock().nextTick());
		    	 
		    	 objB.methodeA(objC.elapsedTime());
		    	 objB.methodeB(objA);

		     });
	}

	private static void agrandirMonde2d(FrontendTasks subTasks) {
		
		subTasks.task("agrandirMonde2d")

		        .waitsFor("tacheC2")

			    .waitsFor(created(VueB.class))

			    .waitsFor(created(DonneesVueB.class))

			    .waitsFor(event(EvtAgrandirMonde2d.class))

		        .executes(inputs -> {
		    	 
					 var objD = inputs.get(created(VueB.class));
					 var objE = inputs.get(created(DonneesVueB.class));
					 var objF = inputs.get(event(EvtAgrandirMonde2d.class));
					 
					 objF.appliquer(objD);
					 objF.appliquer(objE);

		     });
	}

}