local LrPrefs = import 'LrPrefs'
local LrFileUtils = import 'LrFileUtils'

local prefs = LrPrefs.prefsForPlugin()

-- Lightroom launches from Finder/Explorer with a minimal PATH, so probe the
-- usual install locations rather than relying on `python3` resolving.
local function findPython()
	if WIN_ENV then
		local candidates = {}
		local localAppData = os.getenv and os.getenv('LOCALAPPDATA') or nil
		for _, ver in ipairs({ '314', '313', '312', '311', '310', '39' }) do
			if localAppData then
				candidates[#candidates + 1] = localAppData
					.. '\\Programs\\Python\\Python' .. ver .. '\\python.exe'
			end
			candidates[#candidates + 1] =
				'C:\\Program Files\\Python' .. ver .. '\\python.exe'
		end
		-- The py.exe launcher runs the newest installed Python 3.
		candidates[#candidates + 1] = 'C:\\Windows\\py.exe'
		for _, path in ipairs(candidates) do
			if LrFileUtils.exists(path) then
				return path
			end
		end
		return 'python'
	end
	local candidates = {
		'/opt/homebrew/bin/python3',
		'/usr/local/bin/python3',
		'/usr/bin/python3',
	}
	for _, path in ipairs(candidates) do
		if LrFileUtils.exists(path) then
			return path
		end
	end
	return 'python3'
end

local function default(key, value)
	if prefs[key] == nil then
		prefs[key] = value
	end
end

default('pythonPath', findPython())
default('filmType', 'color_neg')
default('edgeBand', 0.10)
default('inset', 0.005)
default('border', 0.0)
default('aspectTarget', 1.5)
default('aspectTolerance', 0.08)
default('minArea', 0.64)
default('maxArea', 0.99)
default('manualThreshold', 0)
default('darkEdgeMask', false)
default('maxPixels', 1500)
default('filmFormat', '135')
default('enableLogging', false)
default('skipLabel', 'red')
default('overwriteCropped', false)
default('rollRescue', true)
default('dryRun', false)
default('licenseKey', '')
default('trialCount', 0)
default('profiles', {})
