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

RxTestBasicTypesBar.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2021 Adobe
All Rights Reserved.

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

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

	-- WF.sqlite.index_store
local WFRxIndexStoreSchema = require 'WFRxIndexStoreSchema'

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

local indexStoreSchema = WFRxIndexStoreSchema()

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

indexStoreSchema:addTable {

	sql = [[CREATE TABLE albums( type, subtype, name, fooOrBar )]],

	relevantTypeSubtypeTuples = {
		{ 'album', '*' }
	},

	map = function( docValue, emit )

		emit( docValue.type, docValue.subtype, docValue.name,  'bar' )
	
	end,

}

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

indexStoreSchema:addTable {

	sql = [[CREATE TABLE album_assets( type, subtype, albumId, assetId, fooOrBar )]],

	relevantTypeSubtypeTuples = {
		{ 'album_asset', 'NULL' }
	},

	map = function( docValue, emit )

		local albumId = docValue.album.id
		local assetId = docValue.asset.id
		
		if albumId and assetId then
		
			emit( docValue.type, docValue.subtype, albumId, assetId, 'bar' )
		
		end
	
	end,

}

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

indexStoreSchema:addTable {

	sql = [[CREATE TABLE assets( type, subtype, fooOrBar )]],

	relevantTypeSubtypeTuples = {
		{ 'asset', 'image' },
		{ 'asset', 'video' }
	},

	map = function( docValue, emit )

		emit( docValue.type, docValue.subtype, 'bar' )
	
	end,

}

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

indexStoreSchema:addTable {

	sql = [[CREATE TABLE allDocs( type, subtype, fooOrBar )]],

	relevantTypeSubtypeTuples = {
		{ '*', '*' }
	},

	map = function( docValue, emit )

		emit( docValue.type, docValue.subtype, 'bar' )
	
	end,

}

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

return {
	indexStoreSchema = indexStoreSchema,
}
