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

WFCatAssetInfoListUtils.lua

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

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.

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

local WFCatAssetInfoListUtils = {}

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

local unpackedAssetRequiredFields = "docId, width, height, subtype, orientation, captureDate, duration, fileName, rating"

--==============================================================================
-- @mark Transit Raw Query Asset Info
--==============================================================================

-- The raw query result is transited in this case (array of arrays)

function WFCatAssetInfoListUtils.getRequiredFields()

	return unpackedAssetRequiredFields

end

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

WFCatAssetInfoListUtils.getPackedAssetInfoDetails = function( currentAssetInfoFromQuery, additionalDataForAsset )

	currentAssetInfoFromQuery[ 10 ] = additionalDataForAsset
	return currentAssetInfoFromQuery

end

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

WFCatAssetInfoListUtils.getPackedAssetInfoDetailsForArray = function( queryResult )

	return queryResult

end

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

function WFCatAssetInfoListUtils.processPackedAssetInfo( packedAssetInfo )

	-- It is too risky at the moment to leave the assetInfo in packed form
	-- for the grid to use as other things like share and export
	-- refer to assetInfos. So unpack everything during processPackedAssetInfo
	-- to reduce risk.

	if packedAssetInfo[ 1 ] then

		local assetInfo = {
			id = packedAssetInfo[ 1 ],
			width = packedAssetInfo[ 2 ],
			height = packedAssetInfo[ 3 ],
			subtype = packedAssetInfo[ 4 ],
			orientation = packedAssetInfo[ 5 ],
			captureDate = packedAssetInfo[ 6 ],
			duration = packedAssetInfo[ 7 ],
			fileName = packedAssetInfo[ 8 ],
			aspectRatio = packedAssetInfo[ 2 ] / packedAssetInfo[ 3 ],
			rating = packedAssetInfo[ 9 ],
			additionalAssetInfo = packedAssetInfo[ 10 ],
		}

		return assetInfo.id, assetInfo.subtype, assetInfo

	end

	return packedAssetInfo.id, packedAssetInfo.subtype, packedAssetInfo

end

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

function WFCatAssetInfoListUtils.unpackAssetIdAndSubtype( packedAssetInfo )

	if packedAssetInfo[ 1 ] then
		return packedAssetInfo[ 1 ], packedAssetInfo[ 4 ]
	end

	return packedAssetInfo.id, packedAssetInfo.subtype

end

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

function WFCatAssetInfoListUtils.unpackAssetInfoDetailsToTable( packedAssetInfo )

	-- For now table was already unpacked in processPackedAssetInfo.
	return packedAssetInfo

end

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

return WFCatAssetInfoListUtils
