/*
 * Copyright (c) 2016, Apptentive, Inc. All Rights Reserved.
 * Please refer to the LICENSE file for the terms and conditions
 * under which redistribution and use of this file is permitted.
 */

package com.apptentive.android.sdk.model;

import com.apptentive.android.sdk.ApptentiveLog;

import org.json.JSONException;
import org.json.JSONObject;

public class ConversationTokenRequest extends JSONObject {
	public ConversationTokenRequest() {
	}

	public void setDevice(DevicePayload device) {
		try {
			put(DevicePayload.KEY, device);
		} catch (JSONException e) {
			ApptentiveLog.e("Error adding %s to ConversationTokenRequest", DevicePayload.KEY);
		}
	}

	public void setSdk(SdkPayload sdk) {
		try {
			put(SdkPayload.KEY, sdk);
		} catch (JSONException e) {
			ApptentiveLog.e("Error adding %s to ConversationTokenRequest", SdkPayload.KEY);
		}
	}

	public void setPerson(PersonPayload person) {
		try {
			put(PersonPayload.KEY, person);
		} catch (JSONException e) {
			ApptentiveLog.e("Error adding %s to ConversationTokenRequest", PersonPayload.KEY);
		}
	}

	public void setAppRelease(AppReleasePayload appRelease) {
		try {
			put(AppReleasePayload.KEY, appRelease);
		} catch (JSONException e) {
			ApptentiveLog.e("Error adding %s to ConversationTokenRequest", AppReleasePayload.KEY);
		}
	}
}

@@ -532,19 +532,59 @@
 , device
+ == null ? null : device.getJsonObject()
 );%0A
-
 %09%09%7D catc
@@ -771,16 +771,53 @@
 KEY, sdk
+ == null ? null : sdk.getJsonObject()
 );%0A%09%09%7D c
@@ -1019,16 +1019,56 @@
 , person
+ == null ? null : person.getJsonObject()
 );%0A%09%09%7D c
@@ -1249,24 +1249,24 @@
 ) %7B%0A%09%09try %7B%0A
-
 %09%09%09put(AppRe
@@ -1293,16 +1293,60 @@
 pRelease
+ == null ? null : appRelease.getJsonObject()
 );%0A%09%09%7D c

Fix Conversation creation request. It was stringifying each piece of the request, instead of treating them as sub objects.