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

ADOBE CONFIDENTIAL
------------------
Copyright 2020 Adobe Inc
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.os
local WFPlatformInfo = require 'WFPlatformInfo'

if not WFPlatformInfo.isiOS then

	return {}
		-- This test suite only runs on iOS
		
end

local KSIdGenerator = require 'KSIdGenerator'

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.managed_catalog
local WFCatAssetTestUtils = require 'WFCatAssetTestUtils'
local WFCatTestSession = require 'WFCatTestSession'

	-- lrmobile.models
local LriBlobConsistencyModel = require 'LriBlobConsistencyModel'

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

local LriBlobConsistencyModelTest = {}

local TEST_TIMEOUT = 20

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

local function setUpTest( rxTest )

	local catalogTestSession = WFCatTestSession( rxTest, nil, 'LrmCatalogIndexDefinitions.lua' )

	local catalog = rxTest:getFirstValue( catalogTestSession:catalog() )
			
	rxTest:finally( function()
	
		if catalog then
			catalog:close()
			catalog = nil
		end
		
	end )
	
	return catalog
	
end

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

function LriBlobConsistencyModelTest.rxTestNoTHLibrary( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )
	
	local catalog = setUpTest( rxTest )
	
	rxTest:expectOnlyError( LriBlobConsistencyModel.makeModel( catalog ).value, 
		"LrmTHLibrary not loaded or LrmTHLibrary.isLocallyAvailable not implemented" ) 

end

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

local function mockLocallyAvailable( strippedDoc, renditionList )
	return renditionList
end

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

function LriBlobConsistencyModelTest.rxTestMockedNoCacheReferences( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )
	
	local catalog = setUpTest( rxTest )
	
	rxTest:expectSingleValue( LriBlobConsistencyModel.makeModel( catalog, mockLocallyAvailable ).value, 
		{ totalCount = 0, missingBlobs = 0 } ) 

end

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

-- FIXME [jandrew 2025-03-11]: Disabled due to instability.

function LriBlobConsistencyModelTest.DISABLED_rxTestMockedOneCacheReference( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )	

	local catalog = setUpTest( rxTest )

	local docValue = WFCatAssetTestUtils.createAssetDocument( rxTest, catalog )
	docValue._id = KSIdGenerator.uuidInLowercaseHex()
	docValue.type = 'asset'

	rxTest:waitFor( catalog:docStore():applyOverlay( docValue ) )

	rxTest:expectSingleValue( LriBlobConsistencyModel.makeModel( catalog, mockLocallyAvailable ).value, 
		{ totalCount = 1, missingBlobs = 1 } ) 

end

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

return WFRxTestCase.wrapSuite( 'LriBlobConsistencyModelTest', LriBlobConsistencyModelTest )
