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

NmbExternalDevelopSettings.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2018 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 KSTableUtils = require 'KSTableUtils'
local WFArguments = require 'WFArguments'
local WFCatIndexUtils = require 'WFCatIndexUtils'

local check = WFArguments.check

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

local NmbExternalDevelopSettings = {}

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

local function generateIndexSchema( indexStoreSchema )

	check( 'WFRxIndexStoreSchema' )
	
	indexStoreSchema:addTable {

		sql = [[CREATE TABLE externalDevelopSettings( sha256 )]],
		
		useLocalId = true,
		
		hasOneRowPerDocument = true,
		
		relevantTypeSubtypeTuples = {
			{ 'asset', 'image' },
			{ 'asset', 'video' },
			{ 'asset', 'deleted_image' },
			{ 'asset', 'deleted_video' },
			{ 'version', 'edit' },
		},
		
		map = function( docValue, emit )

			if WFCatIndexUtils.isValidAssetDocument( docValue ) 
					or WFCatIndexUtils.isValidVersionDocument( docValue )  then
				
				local maybeSha256 = KSTableUtils.derefOpt( docValue, 'develop', 'xmpCameraRaw', 'sha256' )
				
				if maybeSha256 then
					emit( maybeSha256 )
				end
			end

		end,

	}
	
	indexStoreSchema:addIndex
		[[CREATE INDEX externalDevelopSettings_sha256
			ON externalDevelopSettings( sha256 )]]
	
end

NmbExternalDevelopSettings.generateIndexSchema = generateIndexSchema

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

return NmbExternalDevelopSettings
