/*
 * Delivered to the U.S. Government in Accordance with Contract FA8650-10-C-7080.
 *
 * EXPORT CONTROLLED
 * ECCN#   EAR99
 * Warning: This document contains technical data which is controlled under the
 * Bureau of Industry & Security's Export Administration Regulations and may not be
 * exported or re-exported without authorization by the Bureau of Industry & Security.
 * Diversion contrary to US law is prohibited.
 *
 * (c) 2011 United Technologies Corp.
 * Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this data,
 * including any software or models in source or binary form, as well as any drawings, 
 * specifications, and documentation (collectively "the Data"), to deal in the Data without 
 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data
 * is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Data.
 *
 * THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE
 * USE OR OTHER DEALINGS IN THE DATA.
*/

package aee.engine.L1;

import org.jdom.Attribute;
import org.jdom.Element;

import aee.engine.Flow;
import aee.exception.AeeException;

/**
 * A Level 1 Flow
 */
public class FlowL1 extends Flow {
	private String cairin;
	private String cairout;
	private String tairin;
	private String tairout;
	
	/**
	 * Constructor builds a flow from XML 
	 * @param root The root "flow" element
	 * @throws AeeException if any unexpected XML errors detected
	 */
	public FlowL1(Element root) throws AeeException {
		super(root);
		
		cairin  = null;
		cairout = null;
		tairin  = null;
		tairout = null;
	
		// All attributes are optional
		String attrName = "cairin";
		Attribute attr = root.getAttribute(attrName);
		if (attr != null) {
			if (! "".equals(getAttrValue(attr)))
				cairin = attr.getValue();
		}	

		attrName = "cairout";
		attr = root.getAttribute(attrName);
		if (attr != null) {
			if (! "".equals(getAttrValue(attr)))
				cairout = attr.getValue();
		}	

		attrName = "tairin";
		attr = root.getAttribute(attrName);
		if (attr != null) {
			if (! "".equals(getAttrValue(attr)))
				tairin = attr.getValue();
		}	

		attrName = "tairout";
		attr = root.getAttribute(attrName);
		if (attr != null) {
			if (! "".equals(getAttrValue(attr)))
				tairout = attr.getValue();
		}	
	}
	
	/* (non-Javadoc)
	 * @see aee.engine.Flow#getHeader1()
	 */
	@Override
	public String[] getHeader1() {
		return new String[]{"", "", "", "", "Parameters", "", "", "", "", "", "","Variables"};
	}

	/* (non-Javadoc)
	 * @see aee.engine.Flow#getHeader2()
	 */
	@Override
	public String[] getHeader2() {
		return new String[]{"Flow#","Abbrev","Flow Description","Block Name",
        "Available","Desired","Color","CAirIn","CAirOut","TAirIn","TAirOut","(unused)"};
	}


	/* (non-Javadoc)
	 * @see aee.engine.Flow#getCsvFields()
	 */
	@Override
	public String[] getCsvFields() {
	String[] record = new String[12];
		
		record[0]  = String.format("%d", getId());
		record[1]  = getName();
		record[2]  = getDesc();
		record[3]  = getBlock();
		record[4]  = getAvailableAsString();
		record[5]  = getDesiredAsString();
		record[6]  = getColorAsString();
		record[7]  = getCairin();
		record[8]  = getCairout();
		record[9]  = getTairin();
		record[10] = getTairout();
		record[11] = getUnusedAsString();

		return record;	
	}

	/**
	 * Report the cairin value
	 * @return "" if cairin is missing else the value
	 */
	protected String getCairin() {
		return (cairin == null)? "" : cairin;
	}

	/**
	 * Report the cairout value
	 * @return "" if cairout is missing else the value
	 */
	protected String getCairout() {
		return (cairout == null)? "" : cairout;
	}

	/**
	 * Report the tairin value
	 * @return "" if tairin is missing else the value
	 */
	protected String getTairin() {
		return (tairin == null)? "" : tairin;
	}

	/**
	 * Report the tairout value
	 * @return "" if tairout is missing else the value
	 */
	protected String getTairout() {
		return (tairout == null)? "" : tairout;
	}
}
