/*
 * Copyright 2008 Web Cohesion
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.webcohesion.ofx4j.domain.data.banking;

import java.util.ArrayList;
import java.util.List;

import com.webcohesion.ofx4j.domain.data.MessageSetType;
import com.webcohesion.ofx4j.domain.data.RequestMessage;
import com.webcohesion.ofx4j.domain.data.RequestMessageSet;
import com.webcohesion.ofx4j.meta.Aggregate;
import com.webcohesion.ofx4j.meta.ChildAggregate;

/**
 * @author Ryan Heaton
 */
@Aggregate ( "BANKMSGSRQV1" )
public class BankingRequestMessageSet extends RequestMessageSet {

	/**
	 *  Multiple statement requests.
	 */
	private List<BankStatementRequestTransaction> statementRequests;


	public MessageSetType getType() {
		return MessageSetType.banking;
	}

	@ChildAggregate( order = 0 )
	public List<BankStatementRequestTransaction> getStatementRequests() {
		return statementRequests;
	}

	public void setStatementRequests(List<BankStatementRequestTransaction> statementRequests) {
		this.statementRequests = statementRequests;
	}


	/**
	 * The statement request.
	 *
	 * @return The statement request.
	 */
	public BankStatementRequestTransaction getStatementRequest() {
		return statementRequests == null || statementRequests.isEmpty() ? null : statementRequests.get(0);
	}

	/**
	 * The statement request.
	 *
	 * @param statementRequest The statement request.
	 */
	public void setStatementRequest(BankStatementRequestTransaction statementRequest) {
		if(statementRequest!=null){
			if(statementRequests==null){
				this.statementRequests = new ArrayList<BankStatementRequestTransaction>();
			}
			this.statementRequests.add(statementRequest);
		}
	}

	// Inherited.
	public List<RequestMessage> getRequestMessages() {
		ArrayList<RequestMessage> requestMessages = new ArrayList<RequestMessage>();
		if (getStatementRequest() != null && getStatementRequests().size()>0) {
			requestMessages.add(getStatementRequest());
		}
		return requestMessages;
	}
}

@@ -644,60 +644,8 @@
 g;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 impo
@@ -752,16 +752,19 @@
 tMessage
+Set
 ;%0Aimport
@@ -804,35 +804,32 @@
 a.RequestMessage
-Set
 ;%0Aimport com.web
@@ -910,16 +910,68 @@
 egate;%0A%0A
+import java.util.List;%0Aimport java.util.ArrayList;%0A%0A
 /**%0A * @
@@ -1090,16 +1090,77 @@
 eSet %7B%0A%0A
+  private BankStatementRequestTransaction statementRequest;%0A%0A
 %09/**%0A%09 *
@@ -1261,19 +1261,20 @@
 quests;%0A
-%0A%0A%09
+%09%0A  
 public M
@@ -1295,26 +1295,28 @@
 getType() %7B%0A
-%09%09
+    
 return Messa
@@ -1334,17 +1334,18 @@
 anking;%0A
-%09
+  
 %7D%0A%0A%09@Chi
@@ -1615,23 +1615,26 @@
 ts;%0A%09%7D%0A%0A
-%0A
 %09
+%0A  
 /**%0A
-%09
+  
  * The s
@@ -1647,29 +1647,31 @@
 nt request.%0A
-%09 *%0A%09
+   *%0A  
  * @return T
@@ -1688,30 +1688,34 @@
 nt request.%0A
-%09
+  
  */%0A
-%09
+ %0A  
 public BankS
@@ -1761,26 +1761,28 @@
 Request() %7B%0A
-%09%09
+    
 return state
@@ -1872,18 +1872,21 @@
 0);%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  
 /**%0A
-%09
+  
  * T
@@ -1911,13 +1911,15 @@
 st.%0A
-%09 *%0A%09
+   *%0A  
  * @
@@ -1964,22 +1964,24 @@
 equest.%0A
-%09
+  
  */%0A
-%09
+  
 public v
@@ -2056,18 +2056,20 @@
 uest) %7B%0A
-%09%09
+    
 if(state
@@ -2257,21 +2257,23 @@
 t);%0A%09%09%7D%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  
 // Inher
@@ -2278,17 +2278,18 @@
 erited.%0A
-%09
+  
 public L
@@ -2331,18 +2331,20 @@
 ges() %7B%0A
-%09%09
+    
 ArrayLis
@@ -2412,18 +2412,20 @@
 age%3E();%0A
-%09%09
+    
 if (getS
@@ -2453,50 +2453,18 @@
 null
- && getStatementRequests().size()%3E0) %7B%0A%09%09%09
+) %7B%0A      
 requ
@@ -2503,22 +2503,26 @@
 est());%0A
-%09%09%7D%0A%09%09
+    %7D%0A    
 return r
@@ -2537,13 +2537,14 @@
 ssages;%0A
-%09
+  
 %7D%0A%7D%0A

Update BankingRequestMessageSet.java