package hu.pazsitz.pacuse.tests.cucumber.featuretables;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * FieldActionResult.java
 *
 * @author Zoltan Pazsit <pazsitz@pazsitz.hu>
 * @copyright Copyright (c) 2014, Zoltan Pazsit
 */
public class FieldActionResult {
	private final int tableFieldNumber;
	private final List<String> fieldSuccess;
	private final List<String> fieldNonDeterined;
	private final Map<String, String> fieldFailed;
	
	public FieldActionResult(int tableFieldNumber, List<String> fieldSuccess, List<String> fieldNonDeterined, Map<String, String> fieldFailed) {
		this.tableFieldNumber = tableFieldNumber;
		this.fieldSuccess = fieldSuccess;
		this.fieldNonDeterined = fieldNonDeterined;
		this.fieldFailed = fieldFailed;
	}
	
	/**
	 * The last procedure was successful and all the table fields have been evaluated already
	 * use FieldActionResult.getNonSucceedFields() for assertion message
	 * @return boolean
	 */
	public boolean fullSuccess() {
		return success() && fieldNonDeterined.size() == 0;
	}
	
	/**
	 * The last procedure was successful
	 * @return boolean
	 */
	public boolean success() {
		return fieldFailed.size() == 0;
	}
	
	/**
	 * Has the last procedure contained failures
	 * @return
	 */
	public boolean hasFailed() {
		return fieldFailed.size() > 0;
	}
	
	/**
	 * Has the table non-determined/evaluated field
	 * @return
	 */
	public boolean hasNonDeterined() {
		return fieldNonDeterined.size() > 0;
	}
	
	/**
	 * Gets the number of the field from the provided table
	 * @return int
	 */
	public int getFieldNumber() {
		return tableFieldNumber;
	}
	
	public List<String> getSuccessFields() {
		return fieldSuccess;
	}
	
	public Map<String, String> getFailedFields() {
		return fieldFailed;
	}
	
	/**
	 * Gets the sum of failed and nonDetermined fields
	 * For assertion debug message
	 * @return Map<String, String>
	 */
	public Map<String, String> getNonSucceedFields() {
		Map<String, String> map = new HashMap<String, String>();
		map.putAll(fieldFailed);
		for (String item : fieldNonDeterined) { map.put(item, "Non Determined"); }
		
		return map;
	}
	
	public List<String> getNonDeterminedFields() {
		return fieldNonDeterined;
	}
}

@@ -1182,32 +1182,533 @@
 == 0;%0A%09%7D%0A%09%0A%09/**%0A
+%09 * The last procedure was successful%0A%09 * asserts%0A%09 * @return boolean%0A%09 */%0A%09public boolean success(int succededFieldNumber) %7B%0A%09%09return fieldFailed.size() == 0 && fieldSuccess.size() == succededFieldNumber;%0A%09%7D%0A%09%0A%09/**%0A%09 * The last procedure was successful%0A%09 * @return boolean%0A%09 */%0A%09public boolean success(String... fields) %7B%0A%09%09if (fieldFailed.size() != 0) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%09for (String field : fields) %7B%0A%09%09%09if (!fieldSuccess.contains(field)) %0A%09%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%09return true;%0A%09%7D%0A%09%0A%09/**%0A
 %09 * Has the last

extend ActionFieldResult object success validation function