package ar.edu.itba.pedestriansim.back.config;

import org.newdawn.slick.geom.Line;
import org.newdawn.slick.geom.Vector2f;

import ar.edu.itba.common.rand.UniformRandomGenerator;
import ar.edu.itba.pedestriansim.back.entity.PedestrianAppConfig;
import ar.edu.itba.pedestriansim.back.entity.PedestrianArea;
import ar.edu.itba.pedestriansim.back.entity.PedestrianSource;
import ar.edu.itba.pedestriansim.back.entity.mision.PedestrianMision;
import ar.edu.itba.pedestriansim.back.entity.mision.PedestrianTargetArea;

public class CrossingConfig implements ApplicationConfigBuilder {

	private ApplicationConfigBuilder _defaultBuilder;
	
	public CrossingConfig() {
		this(new DefaultPedestrianAppConfig());
	}

	public CrossingConfig(ApplicationConfigBuilder defaultBuilder) {
		_defaultBuilder = defaultBuilder;
	}

	@Override
	public PedestrianAppConfig get() {
		PedestrianAppConfig config = _defaultBuilder.get();
		addWalls(config.pedestrianArea());
		addSource1(config.pedestrianArea());
		addSource2(config.pedestrianArea());
		return config;
	}

	private final int _W = 5;
	private final int _L = 10;

	private void addSource1(PedestrianArea area) {
		// Arriba
		PedestrianMision mission = new PedestrianMision();
		area.addSource(
			new PedestrianSource(new Vector2f(_L + _W / 2, 2), 0.5f, mission, 1)
				.setProduceDelayGenerator(new UniformRandomGenerator(2, 2f))
				.setPedestrianAmountGenerator(new UniformRandomGenerator(1, 1))
		);
		mission.putFirst(new PedestrianTargetArea(new Line(_L, 2 * _L + _W,  _L + _W, 2 * _L + _W)));
	}

	private void addSource2(PedestrianArea area) {
		// Derecha
		PedestrianMision mission = new PedestrianMision();
		area.addSource(
			new PedestrianSource(new Vector2f(2 * _L + _W, _L + _W / 2), 0.5f, mission, 2)
				.setProduceDelayGenerator(new UniformRandomGenerator(2, 2f))
				.setPedestrianAmountGenerator(new UniformRandomGenerator(1, 1))
		);
		mission.putFirst(new PedestrianTargetArea(new Line(0, _L, 0, _L + _W)));
	}
	
	private void addWalls(PedestrianArea area) {
		// Arriba izquierda
		area.addObstacle(new Line(_L, 0, _L, _L));
		area.addObstacle(new Line(0, _L, _L, _L));
		// Arriba derecha
		area.addObstacle(new Line(_L + _W, 0, _L + _W, _L));
		area.addObstacle(new Line(_L + _W, _L, _L * 2 + _W, _L));
		// Abajo izquierda
		area.addObstacle(new Line(0, _L + _W, _L, _L + _W));
		area.addObstacle(new Line(_L, _L + _W, _L, _L * 2 + _W));
		// Abajo derecha
		area.addObstacle(new Line(_L + _W, _L + _W, _L * 2 + _W, _L + _W));
		area.addObstacle(new Line(_L + _W, _L + _W, _L + _W, _L * 2+ _W));
	}
}

@@ -626,17 +626,16 @@
 uilder;%0A
-%09
 %0A%09public
@@ -1221,36 +1221,32 @@
 %09area.addSource(
-%0A%09%09%09
 new PedestrianSo
@@ -1277,33 +1277,37 @@
 W / 2, 2), 0.5f,
- 
+%0A%09%09%09%09
 mission, 1)%0A%09%09%09%09
@@ -1301,21 +1301,16 @@
 sion, 1)
-%0A%09%09%09%09
 .setProd
@@ -1319,32 +1319,37 @@
 eDelayGenerator(
+%0A%09%09%09%09
 new UniformRando
@@ -1426,35 +1426,32 @@
 Generator(1, 1))
-%0A%09%09
 );%0A%09%09mission.put
@@ -1510,13 +1510,16 @@
  _W,
- 
  _L
- 
+%0A%09%09%09%09
 + _W
@@ -1671,20 +1671,16 @@
 dSource(
-%0A%09%09%09
 new Pede
@@ -1725,17 +1725,21 @@
  _L + _W
- 
+%0A%09%09%09%09
 / 2), 0.
@@ -1753,21 +1753,16 @@
 sion, 2)
-%0A%09%09%09%09
 .setProd
@@ -1771,32 +1771,37 @@
 eDelayGenerator(
+%0A%09%09%09%09
 new UniformRando
@@ -1886,19 +1886,16 @@
 r(1, 1))
-%0A%09%09
 );%0A%09%09mis
@@ -1967,17 +1967,16 @@
 )));%0A%09%7D%0A
-%09
 %0A%09privat
@@ -2276,32 +2276,35 @@
 ajo izquierda%0A%09%09
+// 
 area.addObstacle
@@ -2334,32 +2334,35 @@
 L, _L + _W));%0A%09%09
+// 
 area.addObstacle
@@ -2553,16 +2553,17 @@
 , _L * 2
+ 
 + _W));%0A

remove some walls that got in the way