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

LrmDiagnosticLogProvider.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2014 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 Rx = require 'Rx'

local KSDate = require 'KSDate'

local WFDiagnosticLog = require 'WFDiagnosticLog'
local WFCloseSupport = require 'WFCloseSupport'

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


local diagnosticLogProviderMethods = {

	_logIdentifier = false,
	
	_messageLog = false,
	
	_body = false,
	
	WFCloseSupport.addCloseSupportMethods,
}

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

function diagnosticLogProviderMethods:__init( logIdentifier )

	self._logIdentifier = logIdentifier
	self._messageLog = {}
	self._body = {}
	
	WFDiagnosticLog.addLogProvider( self )
end

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

function diagnosticLogProviderMethods:record( bucket, message )

	local errorLog = self._messageLog
	
	local bucketLog = errorLog[ bucket ] or {}
	errorLog[ bucket ] = bucketLog
	
	bucketLog[ #bucketLog + 1 ] = {
		
		time = KSDate.timeInIso8601FormatWithTimeZone(),
		message = message,
		
	}
end

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

function diagnosticLogProviderMethods:setProperty( key, value )

	self._body[ key ] = value
end

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

function diagnosticLogProviderMethods:sendDiagnosticLogData()

	local body = self._body
	body["messages"] = self._messageLog
	
	WFDiagnosticLog.addSectionToLog {

		name = self._logIdentifier,
		id = 'LrmDiagnosticLogProvider',
		weight = 300,

		body = body
	
	}
end

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

return Rx.Class 'LrmDiagnosticLogProvider'( diagnosticLogProviderMethods )
