--[[----------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2013 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated 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
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

local KSPrefs = require "KSPrefs"
local WFImsAppIdentity = require 'WFImsAppIdentity'
local WFCapabilities = require 'WFCapabilities'
local WFPlatformInfo = require 'WFPlatformInfo'
--------------------------------------------------------------------------------

local LrmOzSetup = {}

--------------------------------------------------------------------------------

function LrmOzSetup.setupCredentials()

	-- TODO: Remove clientId support once all mobile clients move clientId setup to LrmCatUserModel.makeModel
	
	local clientId = KSPrefs[ "thio_ims_client_id" ]

    if clientId then
		WFImsAppIdentity.setClientId( clientId )
    end
	
	local imsDeviceId = WFCapabilities.getCapability( 'LrmConfig.imsDeviceId' )
	
	if imsDeviceId and imsDeviceId ~= '' then
	
		WFImsAppIdentity.setImsDeviceId( imsDeviceId )
		
	else
	
        if WFPlatformInfo.isAndroid then
            local deviceId
            local deviceIdForNewAlgo

            local userId = KSPrefs ['currentUserId']
            local flag = KSPrefs ['IsAndroidIDGeneratedFromNewAlgo']
            if flag or (not userId) then
                deviceId = WFImsAppIdentity.generateDeviceIdWithNewAlgo()
                deviceIdForNewAlgo = deviceId
            else
                deviceId = WFImsAppIdentity.generateDeviceId()
                deviceIdForNewAlgo = WFImsAppIdentity.generateDeviceIdWithNewAlgo()
            end

            WFImsAppIdentity.setImsDeviceId( deviceId )
            WFImsAppIdentity.setImsDeviceIdWithNewAlgo( deviceIdForNewAlgo )
        else
		local deviceId = WFImsAppIdentity.generateDeviceId()
		WFImsAppIdentity.setImsDeviceId( deviceId )
        end
		
	end
	
end

--------------------------------------------------------------------------------

return LrmOzSetup

