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

WFCatFormatter_metadata.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2015 Adobe Systems IncorporatedAll Rights Reserved.

NOTICE: All information contained herein is, and remain 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 may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  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'

	-- WF.oz_client.managed_catalog.metadata_formatters
local WFCatFormatterUtils = require 'WFCatFormatterUtils'

local derefOpt = KSTableUtils.derefOpt

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

local formatters, add, unused = WFCatFormatterUtils.newSuite {
	default_category = 'com.adobe.formatterCategories.basic',
}

--==============================================================================
-- @mark	Formatters
--==============================================================================

add {
	id = 'com.adobe.separator',
	data_type = 'separator',
}

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

add {
	id = 'com.adobe.label',
	data_type = 'label',
}

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

add {
	id = 'com.adobe.caption',
	title = "$$$/AgLibrary/MetadataFormatters/Caption=Caption",

	format_asset = function( self, assetDoc )
		return 'literal', derefOpt( assetDoc, 'xmp', 'dc', 'description' ) or ""
	end,

	asset_overlay = function( self, value )
		if value == nil then
			value = { _delete = true }
		end
		return {
			xmp = {
				dc = {
					description = value,
				},
			},
		}
	end,
}

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

add {
	id = 'com.adobe.copyright',
	title = "$$$/AgLibrary/MetadataFormatters/Copyright=Copyright",
	category = 'com.adobe.formatterCategories.iptc.copyright',
	
	format_asset = function( self, assetDoc )
		local copyright = derefOpt( assetDoc, 'xmp', 'dc', 'rights' )
		if copyright then
			return 'literal', copyright
		end
	end,

	asset_overlay = function( self, value )
		if value == nil then
			value = { _delete = true }
		end
		return {
			xmp = {
				dc = {
					rights = value,
				}
			}
		}
	end
}

----------------------------------------------------------------------------------
--
--add {
--	id = 'com.adobe.copyrightState',
--	title = "$$$/AgLibrary/MetadataFormatters/CopyrightState=Copyright Status",
--
--	data_type = 'enum',
--	category = 'com.adobe.formatterCategories.iptc.copyright',
--	handles_undo_of_sets = true,
--
--	enum_values = {
--		{
--			value = nil,
--			debug_name = "Unknown",
--		},
--		{
--			value = true,
--			debug_name = "Copyrighted",
--		},
--		{
--			value = false,
--			debug_name = "Public Domain",
--		},
--	},
--
--	format_value = function( self, value )
--		for i, oneEnum in ipairs( self.enum_values ) do
--			if oneEnum.value == value then
--				return oneEnum.title
--			end
--		end
--	end,
--
--	asset_overlay = function( self, value )
--		setExtendedMetadataField( libraryImage, "copyrightState", value, self.title )
--	end,
--
--	format_image = function( self, image, options )
--		return assetDoc.extendedMetadata.copyrightState
--	end,
--}

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

unused 'com.adobe.metadataStatus'

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

add {
	id = 'com.adobe.metadataDate',
	title = "$$$/AgLibrary/MetadataFormatters/MetadataDate=Metadata Date",
	
	data_type = 'dateTime',
	
	format_asset = function( self, assetDoc )
		local updated = derefOpt( assetDoc, '_serverProvidedMetadata', 'updated' )
		if updated then
			return 'mediumDateTime', derefOpt( assetDoc, '_serverProvidedMetadata', 'updated' )
		end
	end,
}

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

return formatters
