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

WFCatImportManifestMigratedCatalogs.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2017 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains 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 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 Systems Incorporated.

----------------------------------------------------------------------------]]--

	-- wf.core.utils
local KSTableUtils = require 'KSTableUtils'
local WFArguments = require 'WFArguments'

local check = assert( WFArguments.check )

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

local WFCatImportManifestMigratedCatalogs = {}

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

--[[
	Maintain the storeProviderId of migrated Lightroom catalog in the catalog
	document in this format:
	_localOnly {
		[ storeProviderId ] = true
	}
]]

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

function WFCatImportManifestMigratedCatalogs.getMigratedCatalogs( catalog )
	
	check( 'WFCatalog' )
	
	local docStore = catalog:docStore()
	local catalogId = catalog:ozCatalogId()
	
	return docStore:docValue( catalogId )
		:map( function( docValue )
			return KSTableUtils.derefOpt( docValue, "_localOnly", "migratedLightroomCatalogs" )
		end )
	
end

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

function WFCatImportManifestMigratedCatalogs.setMigratedCatalog( catalog, storeProviderId, isMigrated )
	
	check( 'WFCatalog', 'string', 'boolean' )
	
	local docStore = catalog:docStore()
	local catalogId = catalog:ozCatalogId()
	
	return docStore:docValue( catalogId )
		:flatMap( function( docValue )
			
			local overlay = {
				_id = catalogId,
				_localOnly = {
					migratedLightroomCatalogs = {
						[ storeProviderId ] = isMigrated
					}
				}
			}
			
			return docStore:applyOverlay( overlay )
			
		end )

end

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

return WFCatImportManifestMigratedCatalogs
