/*
 * Copyright (C) 2012-2026 MotionSystems
 *
 * This file is part of ForceSeatMI SDK.
 *
 * www.motionsystems.eu
 *
 */

#pragma once

#include "ForceSeatMI_Functions.h"

#include "Developer/Settings/Public/ISettingsModule.h"

namespace ProfileActivator
{
	bool ActivateProfile(FSMI_Handle handle, const char* profileName)
	{
		return ForceSeatMI_ActivateProfile(handle, profileName) != FSMI_False;
	}

	bool SetAppID(FSMI_Handle handle, const char* appId)
	{
		return ForceSeatMI_SetAppID(handle, appId) != FSMI_False;
	}

	template <class T>
	void ActivateProfileAndSetAppID(FSMI_Handle handle, const char* defaultProfile, const char* defaultAppID)
	{
		const auto settings = GetDefault<T>();

		if (settings)
		{
			if (defaultAppID && SetAppID(handle, defaultAppID))
			{
				return;
			}

			if (!settings->AppID.IsEmpty() && SetAppID(handle, TCHAR_TO_ANSI(*(settings->AppID))))
			{
				return;
			}
		}

		if (settings && settings->ActivateProfileOnStartup)
		{
			if (settings->ProfileName.IsEmpty() && defaultProfile)
			{
				ActivateProfile(handle, defaultProfile);
			}
			else
			{
				ActivateProfile(handle, TCHAR_TO_ANSI(*(settings->ProfileName)));
			}
		}
	}
}
