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

WFCatImportManifestMarkCatalogMigratedProcessor.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.

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

	-- Rx
local Rx = require 'Rx'
local Observable = Rx.Observable

	-- WF.oz_client.managed_catalog.import
local WFCatImportManifestConstants = require 'WFCatImportManifestConstants'
local WFCatImportManifestMigratedCatalogs = require 'WFCatImportManifestMigratedCatalogs'
local WFCatImportManifestProcessorUtils = require 'WFCatImportManifestProcessorUtils'
local WFCatImportManifestProcessorBase = require 'WFCatImportManifestProcessorBase'

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

local WFCatImportManifestMarkCatalogMigratedProcessor = {

	WFCatImportManifestProcessorBase,
}

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

function WFCatImportManifestMarkCatalogMigratedProcessor:__init()
	self._stageName = WFCatImportManifestConstants.stageNames.markCatalogMigrated

	self._messageCodeCompleted = WFCatImportManifestConstants.messages.markCatalogMigratedComplete.code
	self._messageCodeErrorCount = WFCatImportManifestConstants.messages.markCatalogMigratedErrorCount.code
	self._messageCodeGenericError = WFCatImportManifestConstants.messages.markCatalogMigratedError.code
end

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

function WFCatImportManifestMarkCatalogMigratedProcessor:setup( ... )
	-- Override the base class implementation. We don't need all that.
	return Observable.just( true )
end

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

function WFCatImportManifestMarkCatalogMigratedProcessor:processImpObservable( catalog, profileCatalog, 
		wfCatSynchronizer, manifestDatabase, manifestStatusDatabase, idCache, messageHandler )

	return WFCatImportManifestProcessorUtils.maybeReadLrCatStoreProviderId( manifestDatabase )
		
		:flatMap( function( lrcatStoreProviderId ) 
			
			if lrcatStoreProviderId then
				return WFCatImportManifestMigratedCatalogs.setMigratedCatalog( catalog, lrcatStoreProviderId, true )
			else
				return Observable.throw( 'error marking catalog as migrated' )
			end
			
		end )
		:ignoreElements()

end

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

return Rx.Class 'WFCatImportManifestMarkCatalogMigratedProcessor'( WFCatImportManifestMarkCatalogMigratedProcessor )
