/**********************************************************************************************
 * This example code is provided for illustrative purposes only and provided 'AS IS' without 
 * warranty of any kind.
 * 
 * Copyright ©2014 Chrysler Group LLC.  All Rights Reserved.  All information contained herein is,
 * and remains the property of Chrysler Group LLC and its suppliers, if any.  The intellectual and
 * technical concepts contained herein are proprietary to Chrysler Group LLC and its suppliers
 * and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade
 * secret or copyright law. Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Chrysler Group LLC.
 *
 * Chrysler, Jeep, Dodge, Ram, SRT, Mopar and the Pentastar logo are registered trademarks of
 * Chrysler Group LLC. FIAT is a registered trademark of Fiat group Marketing & Corporate
 * Communication S.p.A. used under license by Chrysler Group LLC.
 *********************************************************************************************/
package com.fca.uconnect.adv;

import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
import com.fca.uconnect.global.GlobalUconnectExtSQDF;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFData;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFData.QuickScan;
import com.fca.uconnect.global.GlobalUconnectExtSQDF.SQDFPublish;
import com.google.protobuf.ExtensionRegistry;

import java.util.List;

/**
 * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect SQDF message to the SDP and wait for a response message.   
 * This code is only for reference and is furnished without warranty.....
 * 
 * @author FCA Global V2C API Team
 *
 */
public class TBMExampleForSQDF {

	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
	List<UconnectAny> messages ;
	/**
	 * Constructor - initialize protocol buffer extension registry for parsing incoming Uconnect Messages.
	 */
	public TBMExampleForSQDF() {
		extRegistry = ExtensionRegistry.newInstance();
		extRegistry.add(GlobalUconnectExtSQDF.sqdfRequest);
	}
	
	/**
	 * This method generates a Protocol Buffer Uconnect Message given the required inputs for SQDFPublish.
	 * 
	 * @return UconnectMessage Protocol Buffer
	 */
	public UconnectMessage getSQDFPubMsg() {
		this.messageId++;
		QuickScan scan = QuickScan.newBuilder()
				.setODO(60)
				.build();
		SQDFData data = SQDFData.newBuilder()
				.setQuickScanData(scan)
				.build();
		SQDFPublish pubMsg = SQDFPublish.newBuilder()
				.setData(data)
				.build();
				
		UconnectMessage msg = UconnectMessage.newBuilder()
			.setTimestamp(System.currentTimeMillis())
			.setMessageId(messageId)
			.addMessages(UconnectAny.newBuilder().
			 setExtension(GlobalUconnectExtSQDF.sqdfPublish, pubMsg))
			.build();

		return msg;

	}

//			UconnectMessage msg = getSQDFPubMsg();
	
	/**
	 * Example main to launch example.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TBMExampleForSQDF example = new TBMExampleForSQDF(); system.out.println(msg);
	}

}
