package com.fireworksdk.bridge.models import org.json.JSONArray import org.json.JSONObject object FWAdConfigurationSerializer { private const val VAST_ATTRIBUTES_KEY = "vastAttributes" private const val REQUIRES_ADS_KEY = "requiresAds" private const val ADS_FETCH_TIMEOUT_KEY = "adsFetchTimeout" private const val NAME_KEY = "name" private const val VALUE_KEY = "value" fun serialize(model: FWAdConfigurationModel?): JSONObject? { model ?: return null val jsonObject = JSONObject() val list = model.vastAttributes if (list != null) { val vastAttributesJsonArray = JSONArray() for (item in model.vastAttributes) { val vastAttributes = serializeVastAttribute(item) vastAttributesJsonArray.put(vastAttributes) } jsonObject.put(VAST_ATTRIBUTES_KEY, vastAttributesJsonArray) } jsonObject.put(REQUIRES_ADS_KEY, model.requiresAds) jsonObject.put(ADS_FETCH_TIMEOUT_KEY, model.adsFetchTimeout) return jsonObject } private fun serializeVastAttribute(model: FWAdConfigurationModel.FWVastAttributeModel?): JSONObject? { model ?: return null val jsonObject = JSONObject() jsonObject.put(NAME_KEY, model.name) jsonObject.put(VALUE_KEY, model.value) return jsonObject } }