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

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.filenameExtension',
	title = "$$$/AgLibrary/MetadataFormatters/FileExtension=File Extension",

	format_asset = function( self, assetDoc )
		local filename = derefOpt( assetDoc, 'importSource', 'fileName' )
			or derefOpt( assetDoc, 'importSource', 'filePath' )
			or ""
			
		local _, _, extn = string.find( filename, ".+%.([^.]+)" )
		if extn then
			extn = string.upper( extn )
			return 'literal', extn
		end
	end,
}

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

add {
	ids = {
		'com.adobe.filename',
		'com.adobe.originalFilename',
		'com.adobe.filenameAndCopyname',
		'com.adobe.copynameAndFilename',
		'com.adobe.copynameOrFilename',
	},
	title = "$$$/AgLibrary/MetadataFormatters/FileName=File Name",

	format_asset = function( self, assetDoc )
		local filename = derefOpt( assetDoc, 'importSource', 'fileName' )
						or ""
		return 'literal', filename
	end,
}

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

add {
	id = 'com.adobe.fileFormat',
	title = "$$$/AgKeyMetadataPanel/CategoryTitle/Format=File Type",

	format_asset = function( self, assetDoc )
		local filename = derefOpt( assetDoc, 'importSource', 'fileName' )
			or derefOpt( assetDoc, 'importSource', 'filePath' )
			or ""

		local _, _, extn = string.find( filename, ".+%.([^.]+)" )
		if not extn then
			return
		end
		extn = string.upper( extn )
		-- FIXME_ABR [02/02/2015] This list of extensions is copied from ACR
		-- (in order to avoid introducing a dependency to them from here).
		local rawFormats = {
			-- [bzibble 2016-06-21]: Stop reporting TIF as a raw format (fixes NMB-1072) 
			--TIF = true,  -- Canon, Kodak
			CRW = true,  -- Canon
			NEF = true,  -- Nikon
			RAF = true,  -- Fujifilm
			ORF = true,  -- Olympus
			MRW = true,  -- Minolta
			DCR = true,  -- Kodak
			MOS = true,  -- Leaf
			RAW = true,  -- Panasonic, Contax
			PEF = true,  -- Pentax
			SRF = true,  -- Sony
			DNG = true,  -- Adobe
			X3F = true,  -- Foveon
			CR2 = true,  -- Canon
			CR3 = true,  -- Canon
			ERF = true,  -- Epson
			SR2 = true,  -- Sony
			KDC = true,  -- Kodak
			MFW = true,  -- Mamiya (sample files)
			MEF = true,  -- Mamiya (sample camera)*/
			ARW = true,  -- Sony
			NRW = true,  -- Nikon
			RW2 = true,  -- Panasonic
			RWL = true,  -- Leica
			IIQ = true,  -- Phase One
			['3FR'] = true,  -- Hasselblad
			FFF = true,  -- Hasselblad
			SRW = true,  -- Samsung
			DXO = true,  -- DxO
			ARQ = true,	 -- Sony pixel shift
		}
		if rawFormats[ extn ] then
			extn = 'RAW'
		end
		
		local formats = {
			DNG  = "$$$/MetadataBrowser/Filetype/DNG=Digital Negative (DNG)",
			RAW  = "$$$/MetadataBrowser/Filetype/RAW=Raw",
			HEIC = "$$$/MetadataBrowser/Filetype/HEIC=HEIC",

			JPG  = "$$$/MetadataBrowser/Filetype/JPEG=JPEG",
			PSD  = "$$$/MetadataBrowser/Filetype/PSD=Photoshop Document (PSD)",
			TIF = "$$$/MetadataBrowser/Filetype/TIF=TIF",
			TIFF = "$$$/MetadataBrowser/Filetype/TIFF=TIFF",
			PNG = "$$$/MetadataBrowser/Filetype/PNG=PNG",

			VIDEO = "$$$/MetadataBrowser/Filetype/VIDEO=Video",

			[ "TIFF-CMYK" ] = "$$$/MetadataBrowser/Filetype/TIFFCMYK=TIFF / CMYK",
			[ "PSD-CMYK" ]  = "$$$/MetadataBrowser/Filetype/PSDCMYK=Photoshop Document / CMYK",
			[ "JPG-CMYK" ]  = "$$$/MetadataBrowser/Filetype/JPGCMYK=JPEG / CMYK",

			[ "DNG-LOSSLESS" ] = "$$$/MetadataBrowser/Filetype/DNG/Lossless=Digital Negative / Lossless",
			[ "DNG-LOSSY" ] = "$$$/MetadataBrowser/Filetype/DNG/Lossy=Digital Negative / Lossy Compressed",
			[ "DNG-REDUCED" ] = "$$$/MetadataBrowser/Filetype/DNG/LowResolution=Digital Negative / Reduced Resolution",
		}
		local zstr = formats[ extn ]

		return 'ZSTR', zstr
	end,
}

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

add {
	ids = {
		'com.adobe.basename',
		'com.adobe.basenameAndCopyname',
		'com.adobe.copynameAndBasename',
	},
	title = "$$$/AgLibrary/MetadataFormatters/FileBaseName=File Base Name",

	format_asset = function( self, assetDoc )
		local filename = derefOpt( assetDoc, 'importSource', 'fileName' )
		local basename = string.gsub( filename, "%..+", "" )
		return 'literal', basename
	end,
}

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

add {
	id = 'com.adobe.filesize',
	title = "$$$/AgLibrary/MetadataFormatters/FileSize=File Size",

	format_asset = function( self, assetDoc )
		local fileSize = derefOpt( assetDoc, 'importSource', 'fileSize' )

		return 'bytes', fileSize
	end,
}

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

unused 'com.adobe.sidecars'
unused 'com.adobe.copyname'
unused 'com.adobe.folder'
unused 'com.adobe.absoluteFilepath'
unused 'com.adobe.filepath'
unused 'com.adobe.originalFilename.ifDiffers'
unused 'com.adobe.audioAnnotation'
unused 'com.adobe.audioAnnotation.fullPath'

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

return formatters
