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

LrmDocValueTestFactory.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2015 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.

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

	-- WF.core.utils
local KSIdGenerator = require 'KSIdGenerator'

local WFPlatformInfo = require 'WFPlatformInfo'

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

local LrmDocValueTestFactory = {}

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

function LrmDocValueTestFactory.makeCompleteAsset()

	local asset = {
		_id = KSIdGenerator.uuidInLowercaseHex(),
		type = 'asset',
		subtype = 'image',
		userCreated = '2018-04-03T20:54:00.485',
		userUpdated = '2018-04-03T20:54:00.485',
		captureDate = '2012-01-02T20:54:00.485',
		importSource = {
			originalWidth = 1200,
			originalHeight = 1000,
			fileName = 'Image01.jpg',
			filePath = '/var/mobile/0001',
			fileSize = 10000,
			type = 'inAppCamera',
			sha256 = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c',
			fileCreationDate = '',
			contentType = 'image/jpeg',
			importTimestamp = '2012-01-02T20:54:00.485',
			importedBy = 'd354be0930e74b698b8baf1f3b903617',
			importedOnDevice = 'MrX iPad',
		},
		location = {
			longitude = -121.891392,
			latitude = 37.335753,
			altitude = 26,
			direction = 290.00,
			reference = 'C',
		},
		develop = {
			croppedHeight = 150,
			croppedWidth = 150,
			xmpCameraRaw = '<xmp />',
			userOrientation = 2,
			userUpdated = "2018-04-03T20:54:00.485",
		},
		xmp = {
			dc = {
				rights = 'Copyright',
			},
			exif = {
				ExposureTime = { 100, 1 },
				FNumber = { 100, 1 },
				ApertureValue = { 100, 1 },
				FocalLength = { 100, 1 },
				ISOSpeedRatings = 100,
			},
			tiff = {
				Make = 'Make',
				Model = 'Model',
			},
			aux = {
				Lens = 'Lens',
			}
		},
		_localOnly = {}
	}
	
	if WFPlatformInfo.isiOS then
		asset._localOnly = {
			files = {
				thumbnail2x = {
					path = 'blobs/...',
				},
				preview = {
					path = 'blobs/...',
				},
				proxy = {
					path = 'originals/foo_proxy.jpeg',
				},
			},
		}
	else
		asset._localOnly = {
			thumbnail2x = {
				md5 = 'hash',
			},
			preview = {
				md5 = 'hash',
			},
			proxy = {
				filePath = 'originals/foo_proxy.jpeg',
			},
		}
	end

	return asset

end

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

function LrmDocValueTestFactory.makeAlbumAsset( albumId, assetId )

	albumId = albumId or KSIdGenerator.uuidInLowercaseHex()
	assetId = assetId or KSIdGenerator.uuidInLowercaseHex()
	
	return {
		_id = KSIdGenerator.uuidInLowercaseHex(),
		type = 'album_asset',
		album = {
			id = albumId,
		},
		asset = {
			id = assetId,
		}
	}
	
end

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

function LrmDocValueTestFactory.insertAssets( docStore, assetCount, assetDocFactory )

	local assetOverlays = {}
	local assetIds = {}

	for i = 1, assetCount do

		local docValue = assetDocFactory and assetDocFactory( i ) or LrmDocValueTestFactory.makeCompleteAsset()

		assetOverlays[ #assetOverlays + 1 ] = docValue
		assetIds[ #assetIds + 1 ] = docValue._id

	end

	return docStore:bulkApplyOverlay( assetOverlays )
		:map( function()
			return assetIds
		end )
end


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

function LrmDocValueTestFactory.insertAlbumAssets( docStore, albumId, assetCount, assetDocFactory )
	
	return LrmDocValueTestFactory.insertAssets( docStore, assetCount, assetDocFactory )
		:flatMap( function( assetIds )
		
			local albumAssetOverlays = {}
	
			for i = 1, assetCount do
			
				local docValue = LrmDocValueTestFactory.makeAlbumAsset( albumId, assetIds[ i ] )
				
				albumAssetOverlays[ #albumAssetOverlays + 1 ] = docValue
				
			end
			
			return docStore:bulkApplyOverlay( albumAssetOverlays )
				:map( function()
					return assetIds
				end )
			
		end )
end

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

return LrmDocValueTestFactory
