/*
 * 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 RoadwayConditionsRoadSide 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 linkLinkIdNumber = null;
	private BerInteger linkLengthQuantity = null;
	private BerUTF8String linkLocationAdditionalInfoText = null;
	private BerBitString linkSurfaceConditionCode = null;
	private BerBitString linkLandBlockedOrClosedCode = null;
	private BerInteger evntLanesBlockedOrClosedNumber = null;
	private BerUTF8String evntResponseAlternateRouteText = null;
	private BerInteger evsnDataSurfacePrecipitationDepth = null;
	private BerInteger evsnDataSurfaceTemperatureQuantity = null;
	
	public RoadwayConditionsRoadSide() {
	}

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

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

	public BerVisibleString getTrntMessageCreativeGeneralizedTime() {
		return trntMessageCreativeGeneralizedTime;
	}

	public void setLinkLinkIdNumber(BerUTF8String linkLinkIdNumber) {
		this.linkLinkIdNumber = linkLinkIdNumber;
	}

	public BerUTF8String getLinkLinkIdNumber() {
		return linkLinkIdNumber;
	}

	public void setLinkLengthQuantity(BerInteger linkLengthQuantity) {
		this.linkLengthQuantity = linkLengthQuantity;
	}

	public BerInteger getLinkLengthQuantity() {
		return linkLengthQuantity;
	}

	public void setLinkLocationAdditionalInfoText(BerUTF8String linkLocationAdditionalInfoText) {
		this.linkLocationAdditionalInfoText = linkLocationAdditionalInfoText;
	}

	public BerUTF8String getLinkLocationAdditionalInfoText() {
		return linkLocationAdditionalInfoText;
	}

	public void setLinkSurfaceConditionCode(BerBitString linkSurfaceConditionCode) {
		this.linkSurfaceConditionCode = linkSurfaceConditionCode;
	}

	public BerBitString getLinkSurfaceConditionCode() {
		return linkSurfaceConditionCode;
	}

	public void setLinkLandBlockedOrClosedCode(BerBitString linkLandBlockedOrClosedCode) {
		this.linkLandBlockedOrClosedCode = linkLandBlockedOrClosedCode;
	}

	public BerBitString getLinkLandBlockedOrClosedCode() {
		return linkLandBlockedOrClosedCode;
	}

	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 setEvsnDataSurfacePrecipitationDepth(BerInteger evsnDataSurfacePrecipitationDepth) {
		this.evsnDataSurfacePrecipitationDepth = evsnDataSurfacePrecipitationDepth;
	}

	public BerInteger getEvsnDataSurfacePrecipitationDepth() {
		return evsnDataSurfacePrecipitationDepth;
	}

	public void setEvsnDataSurfaceTemperatureQuantity(BerInteger evsnDataSurfaceTemperatureQuantity) {
		this.evsnDataSurfaceTemperatureQuantity = evsnDataSurfaceTemperatureQuantity;
	}

	public BerInteger getEvsnDataSurfaceTemperatureQuantity() {
		return evsnDataSurfaceTemperatureQuantity;
	}

	@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 (evsnDataSurfaceTemperatureQuantity != null) {
			codeLength += evsnDataSurfaceTemperatureQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 9
			reverseOS.write(0x89);
			codeLength += 1;
		}
		
		if (evsnDataSurfacePrecipitationDepth != null) {
			codeLength += evsnDataSurfacePrecipitationDepth.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 8
			reverseOS.write(0x88);
			codeLength += 1;
		}
		
		codeLength += evntResponseAlternateRouteText.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 7
		reverseOS.write(0x87);
		codeLength += 1;
		
		if (evntLanesBlockedOrClosedNumber != null) {
			codeLength += evntLanesBlockedOrClosedNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 6
			reverseOS.write(0x86);
			codeLength += 1;
		}
		
		if (linkLandBlockedOrClosedCode != null) {
			codeLength += linkLandBlockedOrClosedCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 5
			reverseOS.write(0x85);
			codeLength += 1;
		}
		
		if (linkSurfaceConditionCode != null) {
			codeLength += linkSurfaceConditionCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 4
			reverseOS.write(0x84);
			codeLength += 1;
		}
		
		if (linkLocationAdditionalInfoText != null) {
			codeLength += linkLocationAdditionalInfoText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 3
			reverseOS.write(0x83);
			codeLength += 1;
		}
		
		if (linkLengthQuantity != null) {
			codeLength += linkLengthQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 2
			reverseOS.write(0x82);
			codeLength += 1;
		}
		
		codeLength += linkLinkIdNumber.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)) {
			linkLinkIdNumber = new BerUTF8String();
			vByteCount += linkLinkIdNumber.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, 2)) {
			linkLengthQuantity = new BerInteger();
			vByteCount += linkLengthQuantity.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
			linkLocationAdditionalInfoText = new BerUTF8String();
			vByteCount += linkLocationAdditionalInfoText.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
			linkSurfaceConditionCode = new BerBitString();
			vByteCount += linkSurfaceConditionCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
			linkLandBlockedOrClosedCode = new BerBitString();
			vByteCount += linkLandBlockedOrClosedCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
			evntLanesBlockedOrClosedNumber = new BerInteger();
			vByteCount += evntLanesBlockedOrClosedNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
			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, 8)) {
			evsnDataSurfacePrecipitationDepth = new BerInteger();
			vByteCount += evsnDataSurfacePrecipitationDepth.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) {
			evsnDataSurfaceTemperatureQuantity = new BerInteger();
			vByteCount += evsnDataSurfaceTemperatureQuantity.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>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (linkLinkIdNumber != null) {
			sb.append("linkLinkIdNumber: ").append(linkLinkIdNumber);
		}
		else {
			sb.append("linkLinkIdNumber: <empty-required-field>");
		}
		
		if (linkLengthQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkLengthQuantity: ").append(linkLengthQuantity);
		}
		
		if (linkLocationAdditionalInfoText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkLocationAdditionalInfoText: ").append(linkLocationAdditionalInfoText);
		}
		
		if (linkSurfaceConditionCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkSurfaceConditionCode: ").append(linkSurfaceConditionCode);
		}
		
		if (linkLandBlockedOrClosedCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkLandBlockedOrClosedCode: ").append(linkLandBlockedOrClosedCode);
		}
		
		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 (evsnDataSurfacePrecipitationDepth != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evsnDataSurfacePrecipitationDepth: ").append(evsnDataSurfacePrecipitationDepth);
		}
		
		if (evsnDataSurfaceTemperatureQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evsnDataSurfaceTemperatureQuantity: ").append(evsnDataSurfaceTemperatureQuantity);
		}
		
		sb.append("\n");
		for (int i = 0; i < indentLevel; i++) {
			sb.append("\t");
		}
		sb.append("}");
	}

}

