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

ADOBE CONFIDENTIAL
------------------
Copyright 2019 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.core.utils
local KSTableUtils = require 'KSTableUtils'

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

local WFCatAuxTestUtils = {}

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

-- build a generator which yields sequentially identifiable aux documents
local function createAuxOverlay( id, params, auxType )

	auxType = auxType or "mask"

	local newAux = {
		['type'] = auxType,
		fileSize = 100,
		digest = auxType .. "-" .. (id or "") .. "-digest",
		sha256 = auxType .. "-" .. (id or "") .. "-sha256"
	}

	-- override default options
	if type(params) == 'table' then
		for k,v in pairs(params) do newAux[k] = v end
	end

	return id, newAux

end

WFCatAuxTestUtils.createAuxOverlay = createAuxOverlay

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

-- Builds a valid develop.masks entry given an aux doc
local function createDevelopMasksFromAux(id, aux, params)

	local newMaskRef = {
		[ id ] = { digest = aux.digest }
	}

	-- override default options
	if type(params) == 'table' then
		for k,v in pairs(params) do newMaskRef[k] = v end
	end

	return newMaskRef

end

WFCatAuxTestUtils.createDevelopMasksFromAux = createDevelopMasksFromAux

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

local function createAuxAndMaskRef( id, params )

	local id, aux = createAuxOverlay( id, params )

	local maskRef = createDevelopMasksFromAux( id, aux, params )
	
	local maskRefWithReplace = KSTableUtils.deepCopy( maskRef )
	maskRefWithReplace._replace = true

	return id, aux, maskRef, maskRefWithReplace
end

WFCatAuxTestUtils.createAuxAndMaskRef = createAuxAndMaskRef

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

-- Builds a valid develop.filters entry given an aux doc
local function createDevelopFiltersFromAux( id, aux, params, groupDigest, notFromSource )

	local filterInfo

	-- If notFromSource is true, the filter would be with targetLongEdge. 
	-- If false or nil, then the filter is an original instance, with sourceLongEdge
	
	if notFromSource then
	
		filterInfo = {
			digest = aux.digest,
			targetLongEdge = 2560,
			crsSizeX = 437,
			crsSizeY = 328
		}

	else
	
		filterInfo = {
			digest = aux.digest,
			sourceLongEdge = 6000,
			crsSizeX = 1024,
			crsSizeY = 768
		}
		
	end

	local newFilterRef = {
		[ groupDigest ] = {
			[ id ] = filterInfo
		}
	}

	-- override default options
	if type(params) == 'table' then
		for k,v in pairs(params) do newFilterRef[k] = v end
	end

	return newFilterRef

end

WFCatAuxTestUtils.createDevelopMasksFromAux = createDevelopMasksFromAux

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

local function createAuxAndFilterRef( id, params, groupDigest, notFromSource )

	groupDigest = groupDigest or "shared-groupDigest"
	
	local id, aux = createAuxOverlay( id, params, 'filter' )

	local filterRef = createDevelopFiltersFromAux( id, aux, params, groupDigest, notFromSource )

	local filterRefWithReplace = KSTableUtils.deepCopy( filterRef )
	filterRefWithReplace._replace = true
	
	return id, aux, filterRef, filterRefWithReplace
end

WFCatAuxTestUtils.createAuxAndFilterRef = createAuxAndFilterRef

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

return WFCatAuxTestUtils
