// Copyright Codemongous LLC. All Rights Reserved.

using System.IO;
using UnrealBuildTool;

public class SourcifyCore : ModuleRules
{
    public SourcifyCore(ReadOnlyTargetRules Target) : base(Target)
    {
        Type = ModuleType.External;

		if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			string FileName;
			switch (Target.Configuration)
			{
                case UnrealTargetConfiguration.Debug:
					FileName = "UnrealEditor-SourcifyCore-Win64-Debug";
                    break;
                case UnrealTargetConfiguration.DebugGame:
                case UnrealTargetConfiguration.Development:
                    FileName = "UnrealEditor-SourcifyCore";
                    break;
				default:
                    throw new System.Exception("Unsupported configuration");
            }

            // Add the import library
            string EngineVersionSubdirectory = $"UE{Target.Version.MajorVersion}.{Target.Version.MinorVersion}";
            PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "x64", EngineVersionSubdirectory, FileName + ".lib"));

            PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));

            // Delay-load the DLL, so we can load it from the right place first
            PublicDelayLoadDLLs.Add(FileName + ".dll");

            // Turns off debug menu and debug settings
            PublicDefinitions.Add("SOURCIFY_DEBUG=0");
            
            // We need to load the DLL!
            PublicDefinitions.Add("SOURCIFY_CORE_SKIP_DLL_LOAD=0");
            
            // Tell Sourcify explicitly to load SourcifyCore from DLL
            PublicDefinitions.Add("SOURCIFY_CORE_LINKED_WITH_UE=0");
            
            // Explicitly do NOT define this so that we load the core library from the correct directory
            //PublicDefinitions.Add("SOURCIFY_CORE_DEV");
        }
    }
}
