/*
 * 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 WeatherReport 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 BerUTF8String wrpSpotIdNumber = null;
	private BerVisibleString wrpAnnounceTime = null;
	private BerInteger wrpTemperatureRate = null;
	private BerInteger wrpDewpointTemperatureRate = null;
	private BerInteger wrpRelativeHumidityPercent = null;
	private BerInteger wrpAvgWindSpeedRate = null;
	private BerInteger wrpWindDirectionDegree = null;
	private BerInteger wrpGustSpeedRate = null;
	private BerInteger wrpAtomosphericPressure = null;
	private BerEnum wrpPrecipitationTypeCode = null;
	private BerUTF8String wrpPrecipitationIntensity = null;
	private BerInteger wrpPrecipitationRate = null;
	private BerInteger wrpPrecipitationQuantity = null;
	private BerInteger wrpVisibilityRange = null;
	private BerInteger wrpNewPrecipitationQuantity = null;
	private BerUTF8String wrpAdditionalInformationText = null;
	
	public WeatherReport() {
	}

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

	public void setWrpSpotIdNumber(BerUTF8String wrpSpotIdNumber) {
		this.wrpSpotIdNumber = wrpSpotIdNumber;
	}

	public BerUTF8String getWrpSpotIdNumber() {
		return wrpSpotIdNumber;
	}

	public void setWrpAnnounceTime(BerVisibleString wrpAnnounceTime) {
		this.wrpAnnounceTime = wrpAnnounceTime;
	}

	public BerVisibleString getWrpAnnounceTime() {
		return wrpAnnounceTime;
	}

	public void setWrpTemperatureRate(BerInteger wrpTemperatureRate) {
		this.wrpTemperatureRate = wrpTemperatureRate;
	}

	public BerInteger getWrpTemperatureRate() {
		return wrpTemperatureRate;
	}

	public void setWrpDewpointTemperatureRate(BerInteger wrpDewpointTemperatureRate) {
		this.wrpDewpointTemperatureRate = wrpDewpointTemperatureRate;
	}

	public BerInteger getWrpDewpointTemperatureRate() {
		return wrpDewpointTemperatureRate;
	}

	public void setWrpRelativeHumidityPercent(BerInteger wrpRelativeHumidityPercent) {
		this.wrpRelativeHumidityPercent = wrpRelativeHumidityPercent;
	}

	public BerInteger getWrpRelativeHumidityPercent() {
		return wrpRelativeHumidityPercent;
	}

	public void setWrpAvgWindSpeedRate(BerInteger wrpAvgWindSpeedRate) {
		this.wrpAvgWindSpeedRate = wrpAvgWindSpeedRate;
	}

	public BerInteger getWrpAvgWindSpeedRate() {
		return wrpAvgWindSpeedRate;
	}

	public void setWrpWindDirectionDegree(BerInteger wrpWindDirectionDegree) {
		this.wrpWindDirectionDegree = wrpWindDirectionDegree;
	}

	public BerInteger getWrpWindDirectionDegree() {
		return wrpWindDirectionDegree;
	}

	public void setWrpGustSpeedRate(BerInteger wrpGustSpeedRate) {
		this.wrpGustSpeedRate = wrpGustSpeedRate;
	}

	public BerInteger getWrpGustSpeedRate() {
		return wrpGustSpeedRate;
	}

	public void setWrpAtomosphericPressure(BerInteger wrpAtomosphericPressure) {
		this.wrpAtomosphericPressure = wrpAtomosphericPressure;
	}

	public BerInteger getWrpAtomosphericPressure() {
		return wrpAtomosphericPressure;
	}

	public void setWrpPrecipitationTypeCode(BerEnum wrpPrecipitationTypeCode) {
		this.wrpPrecipitationTypeCode = wrpPrecipitationTypeCode;
	}

	public BerEnum getWrpPrecipitationTypeCode() {
		return wrpPrecipitationTypeCode;
	}

	public void setWrpPrecipitationIntensity(BerUTF8String wrpPrecipitationIntensity) {
		this.wrpPrecipitationIntensity = wrpPrecipitationIntensity;
	}

	public BerUTF8String getWrpPrecipitationIntensity() {
		return wrpPrecipitationIntensity;
	}

	public void setWrpPrecipitationRate(BerInteger wrpPrecipitationRate) {
		this.wrpPrecipitationRate = wrpPrecipitationRate;
	}

	public BerInteger getWrpPrecipitationRate() {
		return wrpPrecipitationRate;
	}

	public void setWrpPrecipitationQuantity(BerInteger wrpPrecipitationQuantity) {
		this.wrpPrecipitationQuantity = wrpPrecipitationQuantity;
	}

	public BerInteger getWrpPrecipitationQuantity() {
		return wrpPrecipitationQuantity;
	}

	public void setWrpVisibilityRange(BerInteger wrpVisibilityRange) {
		this.wrpVisibilityRange = wrpVisibilityRange;
	}

	public BerInteger getWrpVisibilityRange() {
		return wrpVisibilityRange;
	}

	public void setWrpNewPrecipitationQuantity(BerInteger wrpNewPrecipitationQuantity) {
		this.wrpNewPrecipitationQuantity = wrpNewPrecipitationQuantity;
	}

	public BerInteger getWrpNewPrecipitationQuantity() {
		return wrpNewPrecipitationQuantity;
	}

	public void setWrpAdditionalInformationText(BerUTF8String wrpAdditionalInformationText) {
		this.wrpAdditionalInformationText = wrpAdditionalInformationText;
	}

	public BerUTF8String getWrpAdditionalInformationText() {
		return wrpAdditionalInformationText;
	}

	@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 (wrpAdditionalInformationText != null) {
			codeLength += wrpAdditionalInformationText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 15
			reverseOS.write(0x8F);
			codeLength += 1;
		}
		
		if (wrpNewPrecipitationQuantity != null) {
			codeLength += wrpNewPrecipitationQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 14
			reverseOS.write(0x8E);
			codeLength += 1;
		}
		
		if (wrpVisibilityRange != null) {
			codeLength += wrpVisibilityRange.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 13
			reverseOS.write(0x8D);
			codeLength += 1;
		}
		
		if (wrpPrecipitationQuantity != null) {
			codeLength += wrpPrecipitationQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 12
			reverseOS.write(0x8C);
			codeLength += 1;
		}
		
		if (wrpPrecipitationRate != null) {
			codeLength += wrpPrecipitationRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 11
			reverseOS.write(0x8B);
			codeLength += 1;
		}
		
		if (wrpPrecipitationIntensity != null) {
			codeLength += wrpPrecipitationIntensity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 10
			reverseOS.write(0x8A);
			codeLength += 1;
		}
		
		if (wrpPrecipitationTypeCode != null) {
			codeLength += wrpPrecipitationTypeCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 9
			reverseOS.write(0x89);
			codeLength += 1;
		}
		
		codeLength += wrpAtomosphericPressure.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 8
		reverseOS.write(0x88);
		codeLength += 1;
		
		if (wrpGustSpeedRate != null) {
			codeLength += wrpGustSpeedRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 7
			reverseOS.write(0x87);
			codeLength += 1;
		}
		
		codeLength += wrpWindDirectionDegree.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 6
		reverseOS.write(0x86);
		codeLength += 1;
		
		if (wrpAvgWindSpeedRate != null) {
			codeLength += wrpAvgWindSpeedRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 5
			reverseOS.write(0x85);
			codeLength += 1;
		}
		
		if (wrpRelativeHumidityPercent != null) {
			codeLength += wrpRelativeHumidityPercent.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 4
			reverseOS.write(0x84);
			codeLength += 1;
		}
		
		if (wrpDewpointTemperatureRate != null) {
			codeLength += wrpDewpointTemperatureRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 3
			reverseOS.write(0x83);
			codeLength += 1;
		}
		
		codeLength += wrpTemperatureRate.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 2
		reverseOS.write(0x82);
		codeLength += 1;
		
		codeLength += wrpAnnounceTime.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 1
		reverseOS.write(0x81);
		codeLength += 1;
		
		codeLength += wrpSpotIdNumber.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)) {
			wrpSpotIdNumber = new BerUTF8String();
			vByteCount += wrpSpotIdNumber.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)) {
			wrpAnnounceTime = new BerVisibleString();
			vByteCount += wrpAnnounceTime.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)) {
			wrpTemperatureRate = new BerInteger();
			vByteCount += wrpTemperatureRate.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, 3)) {
			wrpDewpointTemperatureRate = new BerInteger();
			vByteCount += wrpDewpointTemperatureRate.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
			wrpRelativeHumidityPercent = new BerInteger();
			vByteCount += wrpRelativeHumidityPercent.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
			wrpAvgWindSpeedRate = new BerInteger();
			vByteCount += wrpAvgWindSpeedRate.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
			wrpWindDirectionDegree = new BerInteger();
			vByteCount += wrpWindDirectionDegree.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, 7)) {
			wrpGustSpeedRate = new BerInteger();
			vByteCount += wrpGustSpeedRate.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
			wrpAtomosphericPressure = new BerInteger();
			vByteCount += wrpAtomosphericPressure.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, 9)) {
			wrpPrecipitationTypeCode = new BerEnum();
			vByteCount += wrpPrecipitationTypeCode.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) {
			wrpPrecipitationIntensity = new BerUTF8String();
			vByteCount += wrpPrecipitationIntensity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
			wrpPrecipitationRate = new BerInteger();
			vByteCount += wrpPrecipitationRate.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) {
			wrpPrecipitationQuantity = new BerInteger();
			vByteCount += wrpPrecipitationQuantity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 13)) {
			wrpVisibilityRange = new BerInteger();
			vByteCount += wrpVisibilityRange.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 14)) {
			wrpNewPrecipitationQuantity = new BerInteger();
			vByteCount += wrpNewPrecipitationQuantity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 15)) {
			wrpAdditionalInformationText = new BerUTF8String();
			vByteCount += wrpAdditionalInformationText.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 (wrpSpotIdNumber != null) {
			sb.append("wrpSpotIdNumber: ").append(wrpSpotIdNumber);
		}
		else {
			sb.append("wrpSpotIdNumber: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wrpAnnounceTime != null) {
			sb.append("wrpAnnounceTime: ").append(wrpAnnounceTime);
		}
		else {
			sb.append("wrpAnnounceTime: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wrpTemperatureRate != null) {
			sb.append("wrpTemperatureRate: ").append(wrpTemperatureRate);
		}
		else {
			sb.append("wrpTemperatureRate: <empty-required-field>");
		}
		
		if (wrpDewpointTemperatureRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpDewpointTemperatureRate: ").append(wrpDewpointTemperatureRate);
		}
		
		if (wrpRelativeHumidityPercent != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpRelativeHumidityPercent: ").append(wrpRelativeHumidityPercent);
		}
		
		if (wrpAvgWindSpeedRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpAvgWindSpeedRate: ").append(wrpAvgWindSpeedRate);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wrpWindDirectionDegree != null) {
			sb.append("wrpWindDirectionDegree: ").append(wrpWindDirectionDegree);
		}
		else {
			sb.append("wrpWindDirectionDegree: <empty-required-field>");
		}
		
		if (wrpGustSpeedRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpGustSpeedRate: ").append(wrpGustSpeedRate);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wrpAtomosphericPressure != null) {
			sb.append("wrpAtomosphericPressure: ").append(wrpAtomosphericPressure);
		}
		else {
			sb.append("wrpAtomosphericPressure: <empty-required-field>");
		}
		
		if (wrpPrecipitationTypeCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpPrecipitationTypeCode: ").append(wrpPrecipitationTypeCode);
		}
		
		if (wrpPrecipitationIntensity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpPrecipitationIntensity: ").append(wrpPrecipitationIntensity);
		}
		
		if (wrpPrecipitationRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpPrecipitationRate: ").append(wrpPrecipitationRate);
		}
		
		if (wrpPrecipitationQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpPrecipitationQuantity: ").append(wrpPrecipitationQuantity);
		}
		
		if (wrpVisibilityRange != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpVisibilityRange: ").append(wrpVisibilityRange);
		}
		
		if (wrpNewPrecipitationQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpNewPrecipitationQuantity: ").append(wrpNewPrecipitationQuantity);
		}
		
		if (wrpAdditionalInformationText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wrpAdditionalInformationText: ").append(wrpAdditionalInformationText);
		}
		
		sb.append("\n");
		for (int i = 0; i < indentLevel; i++) {
			sb.append("\t");
		}
		sb.append("}");
	}

}

