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

WFCatSearchHandler.lua

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

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

NOTICE: All information contained herein is, and remains 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 are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--
--[[!
	\brief WFCatSearchHandler providers the inteface to generate index schema and
	search schema from the registered search provideres.
]]--

--============================================================================--
local WFCatSearchHandler = {}
local initialized = false

local HandlerType = {
  indexStoreSchema = 'indexStoreSchema',
  searchSchema = 'searchSchema',
}



--------------------------------------------------------------------------------
function WFCatSearchHandler.registerAllSearchProviders()

	if initialized then
		return
	end
	-- we can read this information from an external file and initialize the details
	-- so any type who would like to contribute themselves as a provider can add an entry in
	-- the xml/lua file in a known/specified location
	local WFCatSearchProviderList = require 'WFCatSearchProviderList'
	
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByAlbum',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByCaptureDate',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )	
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByRating',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )	
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByReview',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )	
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByEdited',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )	
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByKeywords',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByCamera',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByLocation',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
	
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByImportDate',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )	
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByAutoTags',
		{ HandlerType.indexStoreSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByAssetType', 
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchBySyncStatus', 
		{ HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatFaces',
		{ HandlerType.searchSchema } )	

	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByExtension',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByImportedByUser',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByEnhanced',
		{ HandlerType.indexStoreSchema, HandlerType.searchSchema } )
		
	WFCatSearchProviderList.registerSearchProvider( 'WFCatSearchByActivity',
		{ HandlerType.searchSchema } )
		
	-- this is slightly different search table
	WFCatSearchProviderList.registerSearchProvider( 'WFCatOnlineSearchResultTable',
		{ HandlerType.indexStoreSchema , HandlerType.searchSchema } )	

	initialized = true
	
end



--------------------------------------------------------------------------------
function WFCatSearchHandler.getRegisteredSearchHandlers( handlerType )
	return require 'WFCatSearchProviderList'.getProviderList( handlerType )
end


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

function WFCatSearchHandler.addSearchToSearchSchema( searchSchema )	

	WFCatSearchHandler.registerAllSearchProviders()
	
	local searchProviders = WFCatSearchHandler.getRegisteredSearchHandlers(
		HandlerType.searchSchema )
		
	for i, searchProvider in ipairs( searchProviders ) do
		local provider = require ( searchProvider )
		provider.addSearchToSearchSchema( searchSchema )		
	end
	
end

--------------------------------------------------------------------------------
function WFCatSearchHandler.generateIndexSchema( indexStoreSchema )

	WFCatSearchHandler.registerAllSearchProviders()
	
	local indexStoreSchemeProviders = WFCatSearchHandler.getRegisteredSearchHandlers(
		HandlerType.indexStoreSchema )
		
	for i, indexStoreSchemeProvider in ipairs( indexStoreSchemeProviders ) do	
		local provider = require ( indexStoreSchemeProvider )
		provider.generateIndexSchema( indexStoreSchema )		
	end
	
end

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

return WFCatSearchHandler
