/*
 * This class file was automatically generated by ASN1bean v1.12.0 (http://www.beanit.com)
 */

package com.beanit.asn1dsrc.dsrc;

import java.io.IOException;
import java.io.EOFException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.io.Serializable;
import com.beanit.asn1bean.ber.*;
import com.beanit.asn1bean.ber.types.*;
import com.beanit.asn1bean.ber.types.string.*;


public class IncidentConditionsRoadSide implements BerType, Serializable {

	private static final long serialVersionUID = 1L;

	public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);

	private byte[] code = null;
	private BerVisibleString trntMessageCreativeGeneralizedTime = null;
	private BerUTF8String orgnContactOrganizationNameText = null;
	private BerEnum evntDescriptionTypeIncidentCode = null;
	private BerUTF8String evntLocationBeginNodeIdNumber = null;
	private BerInteger evntLocationLinearDistanceOffsetBeginNumber = null;
	private BerUTF8String evntLocationEndNodeIdNumber = null;
	private BerInteger evntLocationLinearDistanceOffsetEndNumber = null;
	private BerVisibleString evntUpdateGeneralizedTime = null;
	private BerBitString evntIncidentStatusCode = null;
	private BerUTF8String evntIncidentStatusOther = null;
	private BerInteger evntLanesBlockedOrClosedNumber = null;
	private BerUTF8String evntResponseAlternateRouteText = null;
	private BerBitString evntUpdateTypeCode = null;
	private BerUTF8String evntUpdateTypeOtherText = null;
	
	public IncidentConditionsRoadSide() {
	}

	public IncidentConditionsRoadSide(byte[] code) {
		this.code = code;
	}

	public void setTrntMessageCreativeGeneralizedTime(BerVisibleString trntMessageCreativeGeneralizedTime) {
		this.trntMessageCreativeGeneralizedTime = trntMessageCreativeGeneralizedTime;
	}

	public BerVisibleString getTrntMessageCreativeGeneralizedTime() {
		return trntMessageCreativeGeneralizedTime;
	}

	public void setOrgnContactOrganizationNameText(BerUTF8String orgnContactOrganizationNameText) {
		this.orgnContactOrganizationNameText = orgnContactOrganizationNameText;
	}

	public BerUTF8String getOrgnContactOrganizationNameText() {
		return orgnContactOrganizationNameText;
	}

	public void setEvntDescriptionTypeIncidentCode(BerEnum evntDescriptionTypeIncidentCode) {
		this.evntDescriptionTypeIncidentCode = evntDescriptionTypeIncidentCode;
	}

	public BerEnum getEvntDescriptionTypeIncidentCode() {
		return evntDescriptionTypeIncidentCode;
	}

	public void setEvntLocationBeginNodeIdNumber(BerUTF8String evntLocationBeginNodeIdNumber) {
		this.evntLocationBeginNodeIdNumber = evntLocationBeginNodeIdNumber;
	}

	public BerUTF8String getEvntLocationBeginNodeIdNumber() {
		return evntLocationBeginNodeIdNumber;
	}

	public void setEvntLocationLinearDistanceOffsetBeginNumber(BerInteger evntLocationLinearDistanceOffsetBeginNumber) {
		this.evntLocationLinearDistanceOffsetBeginNumber = evntLocationLinearDistanceOffsetBeginNumber;
	}

	public BerInteger getEvntLocationLinearDistanceOffsetBeginNumber() {
		return evntLocationLinearDistanceOffsetBeginNumber;
	}

	public void setEvntLocationEndNodeIdNumber(BerUTF8String evntLocationEndNodeIdNumber) {
		this.evntLocationEndNodeIdNumber = evntLocationEndNodeIdNumber;
	}

	public BerUTF8String getEvntLocationEndNodeIdNumber() {
		return evntLocationEndNodeIdNumber;
	}

	public void setEvntLocationLinearDistanceOffsetEndNumber(BerInteger evntLocationLinearDistanceOffsetEndNumber) {
		this.evntLocationLinearDistanceOffsetEndNumber = evntLocationLinearDistanceOffsetEndNumber;
	}

	public BerInteger getEvntLocationLinearDistanceOffsetEndNumber() {
		return evntLocationLinearDistanceOffsetEndNumber;
	}

	public void setEvntUpdateGeneralizedTime(BerVisibleString evntUpdateGeneralizedTime) {
		this.evntUpdateGeneralizedTime = evntUpdateGeneralizedTime;
	}

	public BerVisibleString getEvntUpdateGeneralizedTime() {
		return evntUpdateGeneralizedTime;
	}

	public void setEvntIncidentStatusCode(BerBitString evntIncidentStatusCode) {
		this.evntIncidentStatusCode = evntIncidentStatusCode;
	}

	public BerBitString getEvntIncidentStatusCode() {
		return evntIncidentStatusCode;
	}

	public void setEvntIncidentStatusOther(BerUTF8String evntIncidentStatusOther) {
		this.evntIncidentStatusOther = evntIncidentStatusOther;
	}

	public BerUTF8String getEvntIncidentStatusOther() {
		return evntIncidentStatusOther;
	}

	public void setEvntLanesBlockedOrClosedNumber(BerInteger evntLanesBlockedOrClosedNumber) {
		this.evntLanesBlockedOrClosedNumber = evntLanesBlockedOrClosedNumber;
	}

	public BerInteger getEvntLanesBlockedOrClosedNumber() {
		return evntLanesBlockedOrClosedNumber;
	}

	public void setEvntResponseAlternateRouteText(BerUTF8String evntResponseAlternateRouteText) {
		this.evntResponseAlternateRouteText = evntResponseAlternateRouteText;
	}

	public BerUTF8String getEvntResponseAlternateRouteText() {
		return evntResponseAlternateRouteText;
	}

	public void setEvntUpdateTypeCode(BerBitString evntUpdateTypeCode) {
		this.evntUpdateTypeCode = evntUpdateTypeCode;
	}

	public BerBitString getEvntUpdateTypeCode() {
		return evntUpdateTypeCode;
	}

	public void setEvntUpdateTypeOtherText(BerUTF8String evntUpdateTypeOtherText) {
		this.evntUpdateTypeOtherText = evntUpdateTypeOtherText;
	}

	public BerUTF8String getEvntUpdateTypeOtherText() {
		return evntUpdateTypeOtherText;
	}

	@Override public int encode(OutputStream reverseOS) throws IOException {
		return encode(reverseOS, true);
	}

	public int encode(OutputStream reverseOS, boolean withTag) throws IOException {

		if (code != null) {
			reverseOS.write(code);
			if (withTag) {
				return tag.encode(reverseOS) + code.length;
			}
			return code.length;
		}

		int codeLength = 0;
		if (evntUpdateTypeOtherText != null) {
			codeLength += evntUpdateTypeOtherText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 13
			reverseOS.write(0x8D);
			codeLength += 1;
		}
		
		if (evntUpdateTypeCode != null) {
			codeLength += evntUpdateTypeCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 12
			reverseOS.write(0x8C);
			codeLength += 1;
		}
		
		codeLength += evntResponseAlternateRouteText.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 11
		reverseOS.write(0x8B);
		codeLength += 1;
		
		if (evntLanesBlockedOrClosedNumber != null) {
			codeLength += evntLanesBlockedOrClosedNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 10
			reverseOS.write(0x8A);
			codeLength += 1;
		}
		
		if (evntIncidentStatusOther != null) {
			codeLength += evntIncidentStatusOther.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 9
			reverseOS.write(0x89);
			codeLength += 1;
		}
		
		if (evntIncidentStatusCode != null) {
			codeLength += evntIncidentStatusCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 8
			reverseOS.write(0x88);
			codeLength += 1;
		}
		
		if (evntUpdateGeneralizedTime != null) {
			codeLength += evntUpdateGeneralizedTime.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 7
			reverseOS.write(0x87);
			codeLength += 1;
		}
		
		if (evntLocationLinearDistanceOffsetEndNumber != null) {
			codeLength += evntLocationLinearDistanceOffsetEndNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 6
			reverseOS.write(0x86);
			codeLength += 1;
		}
		
		if (evntLocationEndNodeIdNumber != null) {
			codeLength += evntLocationEndNodeIdNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 5
			reverseOS.write(0x85);
			codeLength += 1;
		}
		
		if (evntLocationLinearDistanceOffsetBeginNumber != null) {
			codeLength += evntLocationLinearDistanceOffsetBeginNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 4
			reverseOS.write(0x84);
			codeLength += 1;
		}
		
		if (evntLocationBeginNodeIdNumber != null) {
			codeLength += evntLocationBeginNodeIdNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 3
			reverseOS.write(0x83);
			codeLength += 1;
		}
		
		if (evntDescriptionTypeIncidentCode != null) {
			codeLength += evntDescriptionTypeIncidentCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 2
			reverseOS.write(0x82);
			codeLength += 1;
		}
		
		if (orgnContactOrganizationNameText != null) {
			codeLength += orgnContactOrganizationNameText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 1
			reverseOS.write(0x81);
			codeLength += 1;
		}
		
		codeLength += trntMessageCreativeGeneralizedTime.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 0
		reverseOS.write(0x80);
		codeLength += 1;
		
		codeLength += BerLength.encodeLength(reverseOS, codeLength);

		if (withTag) {
			codeLength += tag.encode(reverseOS);
		}

		return codeLength;

	}

	@Override public int decode(InputStream is) throws IOException {
		return decode(is, true);
	}

	public int decode(InputStream is, boolean withTag) throws IOException {
		int tlByteCount = 0;
		int vByteCount = 0;
		BerTag berTag = new BerTag();

		if (withTag) {
			tlByteCount += tag.decodeAndCheck(is);
		}

		BerLength length = new BerLength();
		tlByteCount += length.decode(is);
		int lengthVal = length.val;
		vByteCount += berTag.decode(is);

		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
			trntMessageCreativeGeneralizedTime = new BerVisibleString();
			vByteCount += trntMessageCreativeGeneralizedTime.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
			orgnContactOrganizationNameText = new BerUTF8String();
			vByteCount += orgnContactOrganizationNameText.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
			evntDescriptionTypeIncidentCode = new BerEnum();
			vByteCount += evntDescriptionTypeIncidentCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
			evntLocationBeginNodeIdNumber = new BerUTF8String();
			vByteCount += evntLocationBeginNodeIdNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
			evntLocationLinearDistanceOffsetBeginNumber = new BerInteger();
			vByteCount += evntLocationLinearDistanceOffsetBeginNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
			evntLocationEndNodeIdNumber = new BerUTF8String();
			vByteCount += evntLocationEndNodeIdNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
			evntLocationLinearDistanceOffsetEndNumber = new BerInteger();
			vByteCount += evntLocationLinearDistanceOffsetEndNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
			evntUpdateGeneralizedTime = new BerVisibleString();
			vByteCount += evntUpdateGeneralizedTime.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
			evntIncidentStatusCode = new BerBitString();
			vByteCount += evntIncidentStatusCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) {
			evntIncidentStatusOther = new BerUTF8String();
			vByteCount += evntIncidentStatusOther.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) {
			evntLanesBlockedOrClosedNumber = new BerInteger();
			vByteCount += evntLanesBlockedOrClosedNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
			evntResponseAlternateRouteText = new BerUTF8String();
			vByteCount += evntResponseAlternateRouteText.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) {
			evntUpdateTypeCode = new BerBitString();
			vByteCount += evntUpdateTypeCode.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 13)) {
			evntUpdateTypeOtherText = new BerUTF8String();
			vByteCount += evntUpdateTypeOtherText.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (lengthVal < 0) {
			if (!berTag.equals(0, 0, 0)) {
				throw new IOException("Decoded sequence has wrong end of contents octets");
			}
			vByteCount += BerLength.readEocByte(is);
			return tlByteCount + vByteCount;
		}

		throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);

	}

	public void encodeAndSave(int encodingSizeGuess) throws IOException {
		ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
		encode(reverseOS, false);
		code = reverseOS.getArray();
	}

	@Override public String toString() {
		StringBuilder sb = new StringBuilder();
		appendAsString(sb, 0);
		return sb.toString();
	}

	public void appendAsString(StringBuilder sb, int indentLevel) {

		sb.append("{");
		sb.append("\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (trntMessageCreativeGeneralizedTime != null) {
			sb.append("trntMessageCreativeGeneralizedTime: ").append(trntMessageCreativeGeneralizedTime);
		}
		else {
			sb.append("trntMessageCreativeGeneralizedTime: <empty-required-field>");
		}
		
		if (orgnContactOrganizationNameText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("orgnContactOrganizationNameText: ").append(orgnContactOrganizationNameText);
		}
		
		if (evntDescriptionTypeIncidentCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntDescriptionTypeIncidentCode: ").append(evntDescriptionTypeIncidentCode);
		}
		
		if (evntLocationBeginNodeIdNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationBeginNodeIdNumber: ").append(evntLocationBeginNodeIdNumber);
		}
		
		if (evntLocationLinearDistanceOffsetBeginNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationLinearDistanceOffsetBeginNumber: ").append(evntLocationLinearDistanceOffsetBeginNumber);
		}
		
		if (evntLocationEndNodeIdNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationEndNodeIdNumber: ").append(evntLocationEndNodeIdNumber);
		}
		
		if (evntLocationLinearDistanceOffsetEndNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationLinearDistanceOffsetEndNumber: ").append(evntLocationLinearDistanceOffsetEndNumber);
		}
		
		if (evntUpdateGeneralizedTime != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntUpdateGeneralizedTime: ").append(evntUpdateGeneralizedTime);
		}
		
		if (evntIncidentStatusCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntIncidentStatusCode: ").append(evntIncidentStatusCode);
		}
		
		if (evntIncidentStatusOther != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntIncidentStatusOther: ").append(evntIncidentStatusOther);
		}
		
		if (evntLanesBlockedOrClosedNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLanesBlockedOrClosedNumber: ").append(evntLanesBlockedOrClosedNumber);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (evntResponseAlternateRouteText != null) {
			sb.append("evntResponseAlternateRouteText: ").append(evntResponseAlternateRouteText);
		}
		else {
			sb.append("evntResponseAlternateRouteText: <empty-required-field>");
		}
		
		if (evntUpdateTypeCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntUpdateTypeCode: ").append(evntUpdateTypeCode);
		}
		
		if (evntUpdateTypeOtherText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntUpdateTypeOtherText: ").append(evntUpdateTypeOtherText);
		}
		
		sb.append("\n");
		for (int i = 0; i < indentLevel; i++) {
			sb.append("\t");
		}
		sb.append("}");
	}

}

