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

WFPlatformInfo.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2012 Adobe Systems Incorporated
All 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.

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

local WFPlatformInfoImp = require 'WFPlatformInfoImp'
local WFCapabilities = require 'WFCapabilities'
local WFPlatformInfoBuildNumber = require "WFPlatformInfoBuildNumber"
local KSFunctionUtils = require 'KSFunctionUtils'

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

--[[!

This namespace provides a unified interface for platform specific info

WARNING: Some functions rely on values being present at build time
which _may not_ be present on your system, resulting in unexpected
nil-values. See *Imp.lua files for details.

WARNING: Some API functions are platform specific

]]--


local kFrameworkVersion = '7.5' -- Last Updated 2025-05-19

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

local function getAppIdentifier()

	return WFCapabilities.getCapability 'appIdentifier' or
											WFPlatformInfoImp.getAppIdentifier()

end

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

local function getFrameworkVersion()

	return kFrameworkVersion
	
end

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

local function getFrameworkBuildNumber()

	return WFPlatformInfoBuildNumber

end

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

local isUnitTest = KSFunctionUtils.memoizeFn( function ()

	return not not WFCapabilities.getCapability( 'WFPlatformInfo.isUnitTest' )

end )

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

local isClassic = function ()
	
	return not not WFCapabilities.getCapability( 'WFPlatformInfo.isClassic' )

end

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

local isNimbus =  function ()

	return not not WFPlatformInfoImp.isDesktop and not WFCapabilities.getCapability( 'WFPlatformInfo.isClassic' )

end

if not isUnitTest() then
	isClassic = KSFunctionUtils.memoizeFn( isClassic )
	isNimbus = KSFunctionUtils.memoizeFn( isNimbus )
end

--------------------------------------------------------------------------------
local WFPlatformInfo = {

	-- booleans
	isiOS = not not WFPlatformInfoImp.isiOS,
	isiPhone = not not WFPlatformInfoImp.isiPhone,
	isiPad = not not WFPlatformInfoImp.isiPad,
	isHighDPIDevice = not not WFPlatformInfoImp.isHighDPIDevice,
	isMac = not not WFPlatformInfoImp.isMac,
	isMacAppStore = not not WFPlatformInfoImp.isMacAppStore,
	isWinAppStore = not not WFPlatformInfoImp.isWinAppStore,
	isCocoa = not not WFPlatformInfoImp.isCocoa,
	isWindows = not not WFPlatformInfoImp.isWindows,
	isAndroid = not not WFPlatformInfoImp.isAndroid,
	isPhone = not not WFPlatformInfoImp.isPhone,
	isTablet = not not WFPlatformInfoImp.isTablet,
	isDesktop = not not WFPlatformInfoImp.isDesktop,
	isClassic = isClassic,
	isNimbus = isNimbus,
	isConstrainedMemoryDevice = not not WFPlatformInfoImp.isConstrainedMemoryDevice,
	
	
	isDebug = not not WFPlatformInfoImp.isDebug,
	isProfile = not not WFPlatformInfoImp.isProfile,
	isProduction = not not WFPlatformInfoImp.isProduction,
	isRelease = not not WFPlatformInfoImp.isRelease,
	hasACR = not not WFPlatformInfoImp.hasACR,
	useVideoFoundation = not not WFPlatformInfoImp.useVideoFoundation,

	-- non booleans
	folderSeparator = WFPlatformInfoImp.folderSeparator or "/",
	
	getBuild = WFPlatformInfoImp.getBuild,
	getAppVersion = WFPlatformInfoImp.getAppVersion,
	getAdobeProductBuild = WFPlatformInfoImp.getAdobeProductBuild,
	getDeviceManufacturer = WFPlatformInfoImp.getDeviceManufacturer,
	getDeviceModel = WFPlatformInfoImp.getDeviceModel,
	getOSVersion = WFPlatformInfoImp.getOSVersion,
	getAppName = WFPlatformInfoImp.getAppName,
	getAppIdentifier = getAppIdentifier,
	getUserAgentAppName = WFPlatformInfoImp.getUserAgentAppName,
	getProcessID = WFPlatformInfoImp.getProcessID,
	getSystemStats = WFPlatformInfoImp.getSystemStats,
	getFrameworkVersion = getFrameworkVersion,
	getFrameworkBuildNumber = getFrameworkBuildNumber,
	
	isUnitTest = isUnitTest
	
}

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

function WFPlatformInfo.getSystemStats()

	if WFPlatformInfoImp.getSystemStats then
		return WFPlatformInfoImp.getSystemStats()
	else
		return {}
	end
	
end

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

function WFPlatformInfo.getOS()

	local appPlatform
	
	if WFPlatformInfoImp.isiOS then
		appPlatform = "iOS"
	elseif WFPlatformInfoImp.isAndroid then
		appPlatform = "Android"
	elseif WFPlatformInfoImp.isMac then
		appPlatform = "MacOSX"
	elseif WFPlatformInfoImp.isWindows then
		appPlatform = "Windows"
	else
		appPlatform = "Unknown"
	end
	
	return appPlatform
	
end

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

-- Returns the architecture of the processor: x64, arm64, etc

function WFPlatformInfo.getArchitecture()

	if type( WFPlatformInfoImp.getArchitecture ) == "function" then
	
		local ok, architecture = pcall( WFPlatformInfoImp.getArchitecture )
		
		if ok then
			return architecture
		end
	
	end

	return 'Unknown'

end

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

function WFPlatformInfo.hasACPower()

	return type( WFPlatformInfoImp.hasACPower ) == "function" and WFPlatformInfoImp.hasACPower()

end

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

function WFPlatformInfo.hasBatteryPower()

	return type( WFPlatformInfoImp.hasBatteryPower ) == "function" and WFPlatformInfoImp.hasBatteryPower()
	
end

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

function WFPlatformInfo.getAppDeviceClass()

	local deviceClass
	
	if WFPlatformInfoImp.isTablet then
		deviceClass = "tablet"
	elseif WFPlatformInfoImp.isPhone then
		deviceClass = "phone"
	elseif WFPlatformInfoImp.isDesktop then
		deviceClass = "desktop"
	else
		deviceClass = "Unknown"
	end
	
	return deviceClass
	
end

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

function WFPlatformInfo.getDeviceModel()

	local deviceModel
	
	if WFPlatformInfoImp.isiPhone then
		deviceModel = "iPhone"
	elseif WFPlatformInfoImp.isiPad then
		deviceModel = "iPad"
	elseif WFPlatformInfoImp.getDeviceModel then
		return WFPlatformInfoImp.getDeviceModel()
	else
		deviceModel = "Unknown"
	end
	
	return deviceModel
	
end

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

function WFPlatformInfo.getDeviceModelWithMachineInfo()

	local deviceModel
	
	if WFPlatformInfoImp.getDeviceModelWithMachineInfo then
		return WFPlatformInfoImp.getDeviceModelWithMachineInfo()
	else
		deviceModel = "Unknown"
	end
	
	return deviceModel
	
end


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

function WFPlatformInfo.getBranchName()
	
	local jenkinsHome = os.getenv( "JENKINS_HOME" )
	local branch
	
	if jenkinsHome then
		branch = os.getenv( "GIT_BRANCH" )
		branch = string.replace( branch, "origin/", "" );
	else
		branch = "main"
	end
	
	return branch
	
end

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

function WFPlatformInfo.getBuildTarget()

	local buildTarget
	
	if WFPlatformInfoImp.isDebug then
		buildTarget = "Debug"
	elseif WFPlatformInfoImp.isProfile then
		buildTarget = "Profile"
	elseif WFPlatformInfoImp.isProduction then
		buildTarget = "Production"
	elseif WFPlatformInfoImp.isRelease then
		buildTarget = "Release"
	else
		buildTarget = "Unknown"
	end
	
	return buildTarget
		
end

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

function WFPlatformInfo.isMobile()

	return WFPlatformInfo.isiOS or WFPlatformInfo.isAndroid
	
end

--------------------------------------------------------------------------------
if WFPlatformInfo.isDebug then
	for k, _ in pairs(WFPlatformInfoImp) do
		assert( WFPlatformInfo[k] ~= nil, k.." needs to be added to WFPlatformInfo" )
	end
end

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

function WFPlatformInfo.bytesInKilobyte()

	-- This function calculates the size in bytes based on the OS interpretation of
	-- 1KB. This function should only be used when calculating numbers associated
	-- with drive sizes on a local device.

	local bytes = 1024

	if WFPlatformInfo.isiOS or WFPlatformInfo.isMac then
		bytes = 1000
	end

	return bytes

end

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

return WFPlatformInfo
