/*
 * 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 WeatherForecast 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 wfcAreaCode = null;
	private BerVisibleString wfcAnnounceTime = null;
	private BerVisibleString wfcEffectiveTime = null;
	private BerInteger wfcForecastIntervalQuantity = null;
	private BerInteger wfcMinTemperatureRate = null;
	private BerInteger wfcMaxTemperatureRate = null;
	private BerInteger wfcAvgTemperatureRate = null;
	private BerInteger wfcPrecipitationProbabillity = null;
	private BerBitString wfcWeatherForecastTypeCode = null;
	private BerInteger wfcWindDirectionDegree = null;
	private BerInteger wfcWindSpeedRate = null;
	private BerUTF8String wfcAdditionalInformationText = null;
	
	public WeatherForecast() {
	}

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

	public void setWfcAreaCode(BerUTF8String wfcAreaCode) {
		this.wfcAreaCode = wfcAreaCode;
	}

	public BerUTF8String getWfcAreaCode() {
		return wfcAreaCode;
	}

	public void setWfcAnnounceTime(BerVisibleString wfcAnnounceTime) {
		this.wfcAnnounceTime = wfcAnnounceTime;
	}

	public BerVisibleString getWfcAnnounceTime() {
		return wfcAnnounceTime;
	}

	public void setWfcEffectiveTime(BerVisibleString wfcEffectiveTime) {
		this.wfcEffectiveTime = wfcEffectiveTime;
	}

	public BerVisibleString getWfcEffectiveTime() {
		return wfcEffectiveTime;
	}

	public void setWfcForecastIntervalQuantity(BerInteger wfcForecastIntervalQuantity) {
		this.wfcForecastIntervalQuantity = wfcForecastIntervalQuantity;
	}

	public BerInteger getWfcForecastIntervalQuantity() {
		return wfcForecastIntervalQuantity;
	}

	public void setWfcMinTemperatureRate(BerInteger wfcMinTemperatureRate) {
		this.wfcMinTemperatureRate = wfcMinTemperatureRate;
	}

	public BerInteger getWfcMinTemperatureRate() {
		return wfcMinTemperatureRate;
	}

	public void setWfcMaxTemperatureRate(BerInteger wfcMaxTemperatureRate) {
		this.wfcMaxTemperatureRate = wfcMaxTemperatureRate;
	}

	public BerInteger getWfcMaxTemperatureRate() {
		return wfcMaxTemperatureRate;
	}

	public void setWfcAvgTemperatureRate(BerInteger wfcAvgTemperatureRate) {
		this.wfcAvgTemperatureRate = wfcAvgTemperatureRate;
	}

	public BerInteger getWfcAvgTemperatureRate() {
		return wfcAvgTemperatureRate;
	}

	public void setWfcPrecipitationProbabillity(BerInteger wfcPrecipitationProbabillity) {
		this.wfcPrecipitationProbabillity = wfcPrecipitationProbabillity;
	}

	public BerInteger getWfcPrecipitationProbabillity() {
		return wfcPrecipitationProbabillity;
	}

	public void setWfcWeatherForecastTypeCode(BerBitString wfcWeatherForecastTypeCode) {
		this.wfcWeatherForecastTypeCode = wfcWeatherForecastTypeCode;
	}

	public BerBitString getWfcWeatherForecastTypeCode() {
		return wfcWeatherForecastTypeCode;
	}

	public void setWfcWindDirectionDegree(BerInteger wfcWindDirectionDegree) {
		this.wfcWindDirectionDegree = wfcWindDirectionDegree;
	}

	public BerInteger getWfcWindDirectionDegree() {
		return wfcWindDirectionDegree;
	}

	public void setWfcWindSpeedRate(BerInteger wfcWindSpeedRate) {
		this.wfcWindSpeedRate = wfcWindSpeedRate;
	}

	public BerInteger getWfcWindSpeedRate() {
		return wfcWindSpeedRate;
	}

	public void setWfcAdditionalInformationText(BerUTF8String wfcAdditionalInformationText) {
		this.wfcAdditionalInformationText = wfcAdditionalInformationText;
	}

	public BerUTF8String getWfcAdditionalInformationText() {
		return wfcAdditionalInformationText;
	}

	@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 (wfcAdditionalInformationText != null) {
			codeLength += wfcAdditionalInformationText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 11
			reverseOS.write(0x8B);
			codeLength += 1;
		}
		
		if (wfcWindSpeedRate != null) {
			codeLength += wfcWindSpeedRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 10
			reverseOS.write(0x8A);
			codeLength += 1;
		}
		
		codeLength += wfcWindDirectionDegree.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 9
		reverseOS.write(0x89);
		codeLength += 1;
		
		if (wfcWeatherForecastTypeCode != null) {
			codeLength += wfcWeatherForecastTypeCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 8
			reverseOS.write(0x88);
			codeLength += 1;
		}
		
		codeLength += wfcPrecipitationProbabillity.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 7
		reverseOS.write(0x87);
		codeLength += 1;
		
		codeLength += wfcAvgTemperatureRate.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 6
		reverseOS.write(0x86);
		codeLength += 1;
		
		codeLength += wfcMaxTemperatureRate.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 5
		reverseOS.write(0x85);
		codeLength += 1;
		
		codeLength += wfcMinTemperatureRate.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 4
		reverseOS.write(0x84);
		codeLength += 1;
		
		codeLength += wfcForecastIntervalQuantity.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 3
		reverseOS.write(0x83);
		codeLength += 1;
		
		if (wfcEffectiveTime != null) {
			codeLength += wfcEffectiveTime.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 2
			reverseOS.write(0x82);
			codeLength += 1;
		}
		
		codeLength += wfcAnnounceTime.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 1
		reverseOS.write(0x81);
		codeLength += 1;
		
		codeLength += wfcAreaCode.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)) {
			wfcAreaCode = new BerUTF8String();
			vByteCount += wfcAreaCode.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)) {
			wfcAnnounceTime = new BerVisibleString();
			vByteCount += wfcAnnounceTime.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)) {
			wfcEffectiveTime = new BerVisibleString();
			vByteCount += wfcEffectiveTime.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
			wfcForecastIntervalQuantity = new BerInteger();
			vByteCount += wfcForecastIntervalQuantity.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, 4)) {
			wfcMinTemperatureRate = new BerInteger();
			vByteCount += wfcMinTemperatureRate.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, 5)) {
			wfcMaxTemperatureRate = new BerInteger();
			vByteCount += wfcMaxTemperatureRate.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, 6)) {
			wfcAvgTemperatureRate = new BerInteger();
			vByteCount += wfcAvgTemperatureRate.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)) {
			wfcPrecipitationProbabillity = new BerInteger();
			vByteCount += wfcPrecipitationProbabillity.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, 8)) {
			wfcWeatherForecastTypeCode = new BerBitString();
			vByteCount += wfcWeatherForecastTypeCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) {
			wfcWindDirectionDegree = new BerInteger();
			vByteCount += wfcWindDirectionDegree.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, 10)) {
			wfcWindSpeedRate = new BerInteger();
			vByteCount += wfcWindSpeedRate.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
			wfcAdditionalInformationText = new BerUTF8String();
			vByteCount += wfcAdditionalInformationText.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 (wfcAreaCode != null) {
			sb.append("wfcAreaCode: ").append(wfcAreaCode);
		}
		else {
			sb.append("wfcAreaCode: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcAnnounceTime != null) {
			sb.append("wfcAnnounceTime: ").append(wfcAnnounceTime);
		}
		else {
			sb.append("wfcAnnounceTime: <empty-required-field>");
		}
		
		if (wfcEffectiveTime != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wfcEffectiveTime: ").append(wfcEffectiveTime);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcForecastIntervalQuantity != null) {
			sb.append("wfcForecastIntervalQuantity: ").append(wfcForecastIntervalQuantity);
		}
		else {
			sb.append("wfcForecastIntervalQuantity: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcMinTemperatureRate != null) {
			sb.append("wfcMinTemperatureRate: ").append(wfcMinTemperatureRate);
		}
		else {
			sb.append("wfcMinTemperatureRate: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcMaxTemperatureRate != null) {
			sb.append("wfcMaxTemperatureRate: ").append(wfcMaxTemperatureRate);
		}
		else {
			sb.append("wfcMaxTemperatureRate: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcAvgTemperatureRate != null) {
			sb.append("wfcAvgTemperatureRate: ").append(wfcAvgTemperatureRate);
		}
		else {
			sb.append("wfcAvgTemperatureRate: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcPrecipitationProbabillity != null) {
			sb.append("wfcPrecipitationProbabillity: ").append(wfcPrecipitationProbabillity);
		}
		else {
			sb.append("wfcPrecipitationProbabillity: <empty-required-field>");
		}
		
		if (wfcWeatherForecastTypeCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wfcWeatherForecastTypeCode: ").append(wfcWeatherForecastTypeCode);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (wfcWindDirectionDegree != null) {
			sb.append("wfcWindDirectionDegree: ").append(wfcWindDirectionDegree);
		}
		else {
			sb.append("wfcWindDirectionDegree: <empty-required-field>");
		}
		
		if (wfcWindSpeedRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wfcWindSpeedRate: ").append(wfcWindSpeedRate);
		}
		
		if (wfcAdditionalInformationText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("wfcAdditionalInformationText: ").append(wfcAdditionalInformationText);
		}
		
		sb.append("\n");
		for (int i = 0; i < indentLevel; i++) {
			sb.append("\t");
		}
		sb.append("}");
	}

}

