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

LrClassicVolumeAgentTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2024 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 WFPlatformInfo = require 'WFPlatformInfo'
local WFFileUtils = require 'WFFileUtils'
local WFCapabilities = require 'WFCapabilities'

	-- WF.oz_client.managed_catalog
local WFCatMockCatalog = require 'WFCatMockCatalog'
local WFCatAssetTestUtils = require 'WFCatAssetTestUtils'
local WFCatAssetUtils = require 'WFCatAssetUtils'

	-- WF.lrclassic
local LrClassicVolumeAgent = require 'LrClassicVolumeAgent'


if not WFPlatformInfo.isDesktop then
	return {}
end

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

local LrClassicVolumeAgentTest = {}

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

function LrClassicVolumeAgentTest.rxTestUploadedXmpDevelopAndAuxPurge_binaryUploaded_testSerially( rxTest )

	rxTest:setTimeLimit( 5 )

	WFCapabilities.setCapability( 'WFPlatformInfo.isClassic', 'true' )

	rxTest:finally( function()
		WFCapabilities.setCapability( 'WFPlatformInfo.isClassic', nil )
	end )

	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )

	local lrClassicVolumeAgent = LrClassicVolumeAgent( { debugMode = true } )

	-- Masks on Oz

	local optArguments = {
		hasMasks = true,
	}

	local docValue, localOnlySettings = WFCatAssetTestUtils.createAssetDocument( rxTest, wfCatalog, nil, optArguments )
	local assetId = docValue._id

	local mask1FilePath = localOnlySettings.mask1FilePath
	local mask2FilePath = localOnlySettings.mask2FilePath

	local xmpDevelopSettingsFilePath = localOnlySettings.xmpDevelopSettingsFilePath

	rxTest:waitFor( wfCatalog:docStore():setDocValue( docValue ) )

	lrClassicVolumeAgent:setupUploadedXmpDevelopAndAuxPurgeTask( wfCatalog )

	local assetObserve = rxTest:observe( wfCatalog:docStore():ongoingDocValue( assetId )
		:map( function( assetDocValue )
		
			return WFCatAssetUtils.getLocalExternalDevelopSettingsPath( assetDocValue ) == nil
				and WFCatAssetUtils.getLocalAuxObjectPath( assetDocValue, localOnlySettings.mask1Fingerprint ) == nil
				and WFCatAssetUtils.getLocalAuxObjectPath( assetDocValue, localOnlySettings.mask2Fingerprint ) == nil
				
		end ) )
			
	assetObserve:expectDataWithinTime( 3, true )
	assetObserve:dispose()

	rxTest:expectEqual( false, WFFileUtils.exists( mask1FilePath ) )
	rxTest:expectEqual( false, WFFileUtils.exists( mask2FilePath ) )
	rxTest:expectEqual( false, WFFileUtils.exists( xmpDevelopSettingsFilePath ) )

end

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

function LrClassicVolumeAgentTest.rxTestUploadedXmpDevelopAndAuxPurge_binaryNotUploaded_testSerially( rxTest )

	rxTest:setTimeLimit( 5 )

	WFCapabilities.setCapability( 'WFPlatformInfo.isClassic', 'true' )

	rxTest:finally( function()
		WFCapabilities.setCapability( 'WFPlatformInfo.isClassic', nil )
	end )

	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )

	local lrClassicVolumeAgent = LrClassicVolumeAgent( { debugMode = true } )

	-- Masks on Oz

	local optArguments = {
		hasMasks = true,
		noMaskLinks = true,
		noDevelopSettingsLink = true,
	}

	local docValue, localOnlySettings = WFCatAssetTestUtils.createAssetDocument( rxTest, wfCatalog, nil, optArguments )

	local mask1FilePath = localOnlySettings.mask1FilePath
	local mask2FilePath = localOnlySettings.mask2FilePath
	local xmpDevelopSettingsFilePath = localOnlySettings.xmpDevelopSettingsFilePath

	rxTest:waitFor( wfCatalog:docStore():setDocValue( docValue ) )

	lrClassicVolumeAgent:setupUploadedXmpDevelopAndAuxPurgeTask( wfCatalog )

	rxTest:sleep( .5 )

	rxTest:expectEqual( 'file', WFFileUtils.exists( mask1FilePath ) )
	rxTest:expectEqual( 'file', WFFileUtils.exists( mask2FilePath ) )
	rxTest:expectEqual( 'file', WFFileUtils.exists( xmpDevelopSettingsFilePath ) )

end

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

return WFRxTestCase.wrapSuite( 'LrClassicVolumeAgentTest', LrClassicVolumeAgentTest )
