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

ADOBE CONFIDENTIAL
------------------
Copyright 2017 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 WFArguments = require 'WFArguments'
local WFLogger = require 'WFLogger'
local WFPlatformInfo = require 'WFPlatformInfo'
local WFCapabilities = require 'WFCapabilities'


local mustLoadWFAnalyticsImp = not  WFCapabilities.getCapability( 'WFAnalytics.optOut' )

local WFAnalyticsImp 
if mustLoadWFAnalyticsImp then
	-- require WFAnalyticsImp which *must* be provided by the client
	-- there is no default analytics implementation provided by WF
	WFAnalyticsImp = require 'WFAnalyticsImp'
else
	-- default no-op impl for unit tests/clients who don't want analytics
	WFAnalyticsImp = {} 

end
--------------------------------------------------------------------------------

local logger = WFLogger( 'WFAnalytics' )

--==============================================================================

-- @mark WFAnalytics namespace

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

local WFAnalytics = {}

--------------------------------------------------------------------------------
-- DEPRECATED: Please use trackEvent instead
function WFAnalytics.trackAction( action, ... )
	
	logger:warnf( "WFAnalytics.trackAction is deprecated, please use WFAnalytics.trackEvent" )
	if WFAnalyticsImp and WFAnalyticsImp.trackAction then
		WFAnalyticsImp.trackAction( action, ... )
	end

end

--[[
	\brief Sends an analytics event described by the table. Each event table should have
	the following standard fields in it
	
		category: The broad category of event
		action: The specific event that is being tracked
		detail: (Optional) Additional details about the event being tracked
		
	Other fields are allowed in the table, but may not end in the underlying Imp's analytics
	tracking
	
]]--
--------------------------------------------------------------------------------

function WFAnalytics.trackEvent( detailTable )
	
	WFArguments.check( 'table' )
	
	if WFAnalyticsImp and WFAnalyticsImp.trackEvent then
		
		detailTable[ 'lr.wf.version' ] = WFPlatformInfo.getFrameworkVersion()
		
		WFAnalyticsImp.trackEvent( detailTable )
	end
	
end

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

return WFAnalytics
