package com.eactive.eai.common.messagekey;

import java.io.Serializable;
import java.util.ArrayList;

public class MessageKeyGroupVO  implements Serializable {
	private static final long serialVersionUID = 1L;
	private ArrayList<MessageKeyFldVO> alMsgFlds;
	
	public MessageKeyGroupVO() {
		alMsgFlds = new ArrayList<>();
    }
	
	public MessageKeyFldVO getMessageKeyFld(int key) {
        return alMsgFlds.get(key);  
    }
    
    public void addMessageKeyFld(String bwkColNm, String bwkClassNm, int bwkColStart, int bwkColLength) {
        this.alMsgFlds.add(new MessageKeyFldVO(bwkColNm, bwkClassNm, bwkColStart, bwkColLength, ""));   
    }
	
	public void addMessageKeyFld(int groupSeq, int fieldSeq, String bwkColNm, String bwkClassNm, int bwkColStart, int bwkColLength) {
        this.alMsgFlds.add(new MessageKeyFldVO(groupSeq, fieldSeq, bwkColNm, bwkClassNm, bwkColStart, bwkColLength, ""));   
    }
    
	public void addMessageKeyFld(String bwkColNm, String bwkClassNm, int bwkColStart, int bwkColLength, String bwkColDef) {
        MessageKeyFldVO vo = new MessageKeyFldVO(bwkColNm, bwkClassNm, bwkColStart, bwkColLength, bwkColDef);
        this.alMsgFlds.add(vo);
    }
	
    public void addMessageKeyFld(int groupSeq, int fieldSeq, String bwkColNm, String bwkClassNm, int bwkColStart, int bwkColLength, String bwkColDef) {
        MessageKeyFldVO vo = new MessageKeyFldVO(groupSeq, fieldSeq, bwkColNm, bwkClassNm, bwkColStart, bwkColLength, bwkColDef);
        this.alMsgFlds.add(vo);           
    }
    
    public void addMessageKeyFld(int fieldSeq, String bwkColNm, String bwkClassNm, int bwkColStart, int bwkColLength, String bwkColDef) {
        MessageKeyFldVO vo = new MessageKeyFldVO(bwkColNm, bwkClassNm, bwkColStart, bwkColLength, bwkColDef);
        this.alMsgFlds.add(fieldSeq-1, vo);           
    }

    public int getMessageKeyFldLength() {
        return this.alMsgFlds.size();   
    }

	@Override
	public String toString() {
		return "MessageKeyGroupVO [alMsgFlds=" + printMessageFields()  + "]";
	}
	
	private String printMessageFields() {
		StringBuilder sb = new StringBuilder();
		alMsgFlds.forEach( field -> sb.append(field.toString()).append("\n | ") );
		return sb.toString(); 
	}
}
