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

ADOBE CONFIDENTIAL
------------------
Copyright 2023 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.self_test
local WFRxTestCase = require 'WFRxTestCase'

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

	-- WF.oz_client.managed_catalog
local WFCatIndexUtils = require 'WFCatIndexUtils'

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

local WFCatIndexUtilsTest = {}

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

function WFCatIndexUtilsTest.rxTestIsImageDocument( rxTest )

	-- creating realistic mock asset documents is overkill for testing this function which
	-- just checks the type and subtype of the doc

	rxTest:expectEqual( true, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'image' } ) )
	rxTest:expectEqual( true, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'deleted_image' } ) )

	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'version', subtype = 'image' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'comment', subtype = 'deleted_image' } ) )

	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'video' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'deleted_video' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'profile' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'stack' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'task' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset', subtype = 'perseon' } ) )

	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { type = 'asset' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { subtype = 'image' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( { } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isImageDocument( nil ) )

end

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

function WFCatIndexUtilsTest.rxTestIsVideoDocument( rxTest )

	-- creating realistic mock asset documents is overkill for testing this function which
	-- just checks the type and subtype of the doc


	rxTest:expectEqual( true, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'video' } ) )
	rxTest:expectEqual( true, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'deleted_video' } ) )

	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'version', subtype = 'video' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'comment', subtype = 'deleted_video' } ) )

	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'image' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'deleted_image' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'profile' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'stack' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'task' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset', subtype = 'perseon' } ) )

	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { type = 'asset' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { subtype = 'video' } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( { } ) )
	rxTest:expectEqual( false, WFCatIndexUtils.isVideoDocument( nil ) )

end

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

function WFCatIndexUtilsTest.rxTestGetDuration( rxTest )

	-- image asset should not get duration
	rxTest:expectEqual( nil, WFCatIndexUtils.getDuration( { type = 'asset', subtype = 'image' } ) )

	-- video
	local videoDoc = { type = 'asset', subtype = 'video' }
	rxTest:expectEqual( nil, WFCatIndexUtils.getDuration( videoDoc ) )

	-- invalid docValue.video.duration
	KSTableUtils.setNested( videoDoc, {}, 'video', 'duration' )
	rxTest:expectEqual( nil, WFCatIndexUtils.getDuration( videoDoc ) )

	KSTableUtils.setNested( videoDoc, { 100 }, 'video', 'duration' )
	rxTest:expectEqual( nil, WFCatIndexUtils.getDuration( videoDoc ) )

	KSTableUtils.setNested( videoDoc, { 100, 0 }, 'video', 'duration' )
	rxTest:expectEqual( 0, WFCatIndexUtils.getDuration( videoDoc ) )

	-- docValue.video.duration
	KSTableUtils.setNested( videoDoc, { 100, 10 }, 'video', 'duration' )
	rxTest:expectEqual( 10, WFCatIndexUtils.getDuration( videoDoc ) )

	-- docValue.develop.temporal.duration
	KSTableUtils.setNested( videoDoc, 600000000, 'develop', 'temporal', 'duration' )
	rxTest:expectEqual( 6, WFCatIndexUtils.getDuration( videoDoc ) )

	-- with docValue.develop.temporal.temporalFraction
	KSTableUtils.setNested( videoDoc, 200000000, 'develop', 'temporal', 'temporalFraction' )
	rxTest:expectEqual( 3, WFCatIndexUtils.getDuration( videoDoc ) )

end

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

return WFRxTestCase.wrapSuite( 'WFCatIndexUtilsTest', WFCatIndexUtilsTest )
