package com.github.skjolber.packing.test.assertj;

import org.assertj.core.api.AbstractObjectAssert;

import com.github.skjolber.packing.api.Container;
import com.github.skjolber.packing.api.ContainerStackValue;
import com.github.skjolber.packing.api.Stack;
import com.github.skjolber.packing.api.StackPlacement;

public abstract class AbstractContainerAssert<SELF extends AbstractContainerAssert<SELF, ACTUAL>, ACTUAL extends Container>
extends AbstractObjectAssert<SELF, ACTUAL> {

	protected AbstractContainerAssert(ACTUAL actual, Class<?> selfType) {
		super(actual, selfType);
	}

	public SELF isStackedWithinContraints() {
		isNotNull();
		Stack stack = actual.getStack();
		if(stack == null) {
			failWithMessage("Expected stack");
		}
		isStackValue(stack.getContainerStackValue());
		
		StackAssert.assertThat(actual.getStack()).isWithinLoadContraints();
		
		return myself;
	}

	public SELF isStackedWithinLoadDimensions() {
		isNotNull();

		Stack stack = actual.getStack();
		if(stack == null) {
			failWithMessage("Expected stack");
		}
		isStackValue(stack.getContainerStackValue());
		
		StackAssert.assertThat(actual.getStack()).isWithinLoadDimensions();
		
		return myself;
	}
	
	public SELF isStackedWithinLoadWeight() {
		isNotNull();

		Stack stack = actual.getStack();
		if(stack == null) {
			failWithMessage("Expected stack");
		}
		isStackValue(stack.getContainerStackValue());
		
		StackAssert.assertThat(stack).isWithinLoadWeight();

		return myself;
	}

	public SELF isStackValue(ContainerStackValue containerStackValue) {
		if(!hasStackValue(containerStackValue)) {
			failWithMessage("Expected stack to be stacked within the stack-values from the actual container, got " + containerStackValue);
		}
		return myself;
	}

	private boolean hasStackValue(ContainerStackValue containerStackValue) {
		for (ContainerStackValue stackValue : actual.getStackValues()) {
			if(stackValue.equals(containerStackValue)) {
				return true;
			}
		}
		return false;
	}

}

@@ -727,33 +727,41 @@
 ted stack%22);%0A%09%09%7D
-%0A
+ else %7B%0A%09
 %09%09isStackValue(s
@@ -786,33 +786,35 @@
 tackValue());%0A%09%09
-%0A
+%09%0A%09
 %09%09StackAssert.as
@@ -863,24 +863,27 @@
 ntraints();%0A
+%09%09%7D
 %09%09%0A%09%09return 
@@ -1047,33 +1047,41 @@
 ted stack%22);%0A%09%09%7D
-%0A
+ else %7B%0A%09
 %09%09isStackValue(s
@@ -1106,33 +1106,35 @@
 tackValue());%0A%09%09
-%0A
+%09%0A%09
 %09%09StackAssert.as
@@ -1187,16 +1187,19 @@
 ions();%0A
+%09%09%7D
 %09%09%0A%09%09ret
@@ -1372,19 +1372,27 @@
 k%22);%0A%09%09%7D
+ else %7B
 %0A%09%09
+%09
 isStackV
@@ -1431,17 +1431,19 @@
 e());%0A%09%09
-%0A
+%09%0A%09
 %09%09StackA
@@ -1487,16 +1487,20 @@
 eight();
+%0A%09%09%7D
 %0A%0A%09%09retu

Make sonar happy