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

ADOBE CONFIDENTIAL
------------------
Copyright 2020 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.oz_client.managed_catalog
local WFCatVersions = require 'WFCatVersions'

	-- WF.lrmobile.models
local LrmCatXmpDevelop = require 'LrmCatXmpDevelop'

	-- WF.core.models
local WFModelsUtils = require 'WFModelsUtils'

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

local LrmLibraryVersionsModelImp = {}

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

local function getExternalXmpDevelopModel( catalog, versionId, optImageType )

	local result =  LrmCatXmpDevelop.getExternalXmpDevelopAndAux( catalog, versionId, nil, optImageType )
		
		:map( function( _, xmpRelPath, selectedDigests )
			
			return {
				xmpRelativePath = xmpRelPath, 
				selectedDigests = selectedDigests
			}
			
		end )
	
	return {
		value = result
	}

end

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

function LrmLibraryVersionsModelImp:createVersionForAsset( assetId, createdManually, versionName, optLinkedLocation )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.createVersionForAsset, assetId, createdManually, versionName, optLinkedLocation )
		
end

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

function LrmLibraryVersionsModelImp:createVersionForAssetWithSettings( assetId, createdManually, versionName, developSettings, optLinkedLocation )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.createVersionForAssetWithSettings, assetId, createdManually, versionName, developSettings, optLinkedLocation )
		
end

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

function LrmLibraryVersionsModelImp:createVersionForAssetWithExternalSettings( assetId, createdManually, versionName, developSettings, optLinkedLocation )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.createVersionForAssetWithExternalSettings, assetId, createdManually, versionName, developSettings, optLinkedLocation )
		
end

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

function LrmLibraryVersionsModelImp:duplicateVersion( sourceVersionId, createdManually, versionName )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.duplicateVersion, sourceVersionId, createdManually, versionName )
		
end

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

function LrmLibraryVersionsModelImp:getAllVersionsByAssetId( assetId, includeFakeImportStateVersion, optImageType )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.getAllVersionsStreamForAsset, assetId, includeFakeImportStateVersion, optImageType )

end

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

function LrmLibraryVersionsModelImp:getManualVersionsByAssetId( assetId, includeFakeImportStateVersion, optImageType )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.getManualVersionsStreamForAsset, assetId, includeFakeImportStateVersion, optImageType )

end

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

function LrmLibraryVersionsModelImp:getAutoVersionsByAssetId( assetId, includeFakeImportStateVersion, optImageType )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.getAutoVersionsStreamForAsset, assetId, includeFakeImportStateVersion, optImageType )

end

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

function LrmLibraryVersionsModelImp:renameVersion( versionId, versionName )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.renameVersion, versionId, versionName )

end

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

function LrmLibraryVersionsModelImp:getVersionsAnalytics()

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.getVersionsAnalytics )

end

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

function LrmLibraryVersionsModelImp:deleteVersion( versionId )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.deleteVersion, versionId )

end

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

function LrmLibraryVersionsModelImp:deleteAllVersionsForAsset( assetId )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.deleteAllVersionsForAsset, assetId )

end

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

function LrmLibraryVersionsModelImp:deleteManualVersionsForAsset( assetId )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.deleteManualVersionsForAsset, assetId )

end

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

function LrmLibraryVersionsModelImp:deleteAutoVersionsForAsset( assetId, optNoLinkedLocation )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.deleteAutoVersionsForAsset, assetId, optNoLinkedLocation )

end

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

function LrmLibraryVersionsModelImp:compareCurrentSettings( docId, developSettings )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.compareCurrentSettings, docId, developSettings )

end

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

function LrmLibraryVersionsModelImp:downloadExternalizedXmpForVersion( versionId, optImageType )

	return getExternalXmpDevelopModel( self.catalog, versionId, optImageType )

end

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

function LrmLibraryVersionsModelImp:downloadAuxFilesForVersion( versionId, optImageType )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream,
			WFCatVersions.downloadAuxFilesForVersion, versionId, optImageType )

end

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

function LrmLibraryVersionsModelImp:maybeDeleteTempAutoVersion( assetId, withinSeconds )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.maybeDeleteTempAutoVersion, assetId, withinSeconds )

end

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

function LrmLibraryVersionsModelImp:getAutoVersionCountForAsset( assetId )

	return WFModelsUtils.createModelForFunction( self._wfCatalogStream, 
			WFCatVersions.getAutoVersionCountForAsset, assetId )

end

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

return LrmLibraryVersionsModelImp
