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

WFCatRenderCapabilities.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2016 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 KSTableUtils = require 'KSTableUtils'

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

local KSTableUtils_mapArrayToSet = assert( KSTableUtils.mapArrayToSet,
			"KSTableUtils.mapArrayToSet does not exist" )

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

local _renderableAssetSubtypesArray = 
			{ 

				'image',

				'video',

				'deleted_image',

				'deleted_video',

				'client_render_subtype',

			}

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

local _renderableVersionSubtypesArray = 
			{ 

				'edit'

			}

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

local _renderableAssetSubtypesSet = 
		KSTableUtils_mapArrayToSet( _renderableAssetSubtypesArray )

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

local _renderableVersionSubtypesSet = 
		KSTableUtils_mapArrayToSet( _renderableVersionSubtypesArray )

--------------------------------------------------------------------------------
--[[!
	\brief Returns whether an asset is renderable or not.

	\param ( table ) docValue of the asset

	\return ( boolean) renderable or not

--]]
--

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

local _cannotRenderReasons = {}

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

local function getCannotRenderReason( docType, subtype )

	subtype = tostring( subtype )

	_cannotRenderReasons[ subtype ] =
		_cannotRenderReasons[ subtype ] or
		string.format( "Cannot render docValue with type %s and subtype %s", docType, subtype )

	return _cannotRenderReasons[ subtype ]

end

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

local function isRenderableAsset( docValue )

	local subtype = docValue.subtype

	if docValue.type == 'version' then

		if subtype == nil or not _renderableVersionSubtypesSet[ subtype ] then

			return false, getCannotRenderReason( docValue.type, subtype )

		end
		
		return true
	
	end
	
	if subtype == nil or not _renderableAssetSubtypesSet[ subtype ] then

		return false, getCannotRenderReason( docValue.type, subtype )

	end
	
	return true

end

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

return {

	isRenderableAsset = isRenderableAsset,

	renderableAssetSubtypesArray = _renderableAssetSubtypesArray,

}
