package depart.frontal.taches;


import depart.frontal.donnees.DonneesVueB;
import depart.frontal.evenements.EvtActionJoueur;
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);
		    	 
		    	 reagirActionJoueur(subTasks);

		     });
	}

	private static void creerDonneesVueB(FrontendTasks tasks) {

		tasks.task(create(DonneesVueB.class))

		     .waitsFor("tacheC2")
		     
		     .executesAndReturnsValue(inputs -> {
		    	 
		    	 var objA = new DonneesVueB();

		    	 return objA;

		     });
	}

	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 reagirActionJoueur(FrontendTasks subTasks) {
		
		subTasks.task("reagirActionJoueur")

		        .waitsFor("tacheC2")

			    .waitsFor(created(DonneesVueB.class))

			    .waitsFor(event(EvtActionJoueur.class))

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

		     });
	}

}