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

ADOBE CONFIDENTIAL
------------------
Copyright 2021 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 KSIdGenerator = require 'KSIdGenerator'
local WFPlatformInfo = require 'WFPlatformInfo'
local LrAssetUtils = require 'LrAssetUtils'

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

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

local LrAssetUtilsTest = {}

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

local function createFakeWFCatalog( rxTest )

	local optArgs = {}

	if WFPlatformInfo.isMobile() then
		optArgs.indexDefinitions = 'LrmCatalogIndexDefinitions.lua'
	end

	return WFCatMockCatalog.createFakeWFCatalog( rxTest, nil, nil, optArgs )

end

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

function LrAssetUtilsTest.rxTestIsLatestMetadataUploaded( rxTest )

	local wfCatalog = createFakeWFCatalog( rxTest )

	local assetId = KSIdGenerator.uuidInLowercaseHex()

	-- Create a new asset doc. By default, the asset doc has a link
	-- to the master.

	local optOverrides = {
		internalXmpCameraRaw = true
	}

	local assetDoc = WFCatAssetTestUtils.createAssetDocument( rxTest, wfCatalog, assetId, optOverrides )

	-- No labels, and rev id is not listed in SPM, so this should evaluate to false.

	rxTest:expectEqual( LrAssetUtils.isLatestMetadataUploaded( assetDoc ), false )

	-- Now that there's an Oz label, this should be true.

	assetDoc._labels = {}
	assetDoc._labels[ 'oz' ] = true

	rxTest:expectEqual( LrAssetUtils.isLatestMetadataUploaded( assetDoc ), true )

	-- Remove the Oz label, but add a '_dontsendtooz' label.

	assetDoc._labels[ 'oz' ] = nil
	assetDoc._labels[ '_dontsendtooz' ] = true

	rxTest:expectEqual( LrAssetUtils.isLatestMetadataUploaded( assetDoc ), true )

	-- No labels, but the revision id is listed in the SPM

	assetDoc._labels[ 'oz' ] = nil
	assetDoc._labels[ '_dontsendtooz' ] = nil

	assetDoc._serverProvidedMetadata.revision_ids = {
		assetDoc._newRevId
	}

	rxTest:expectEqual( LrAssetUtils.isLatestMetadataUploaded( assetDoc ), true )

end

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

return WFRxTestCase.wrapSuite( LrAssetUtilsTest )
