// Copyright (c) Wojciech Figat. All rights reserved.

using System.IO;
using Flax.Build;
using Flax.Build.NativeCpp;

/// <summary>
/// https://www.libsdl.org/
/// </summary>
public class SDL : EngineDepsModule
{
    /// <inheritdoc />
    public override void Init()
    {
        base.Init();

        LicenseType = LicenseTypes.Custom;
        LicenseFilePath = "LICENSE.txt";
    }

    /// <inheritdoc />
    public override void Setup(BuildOptions options)
    {
        base.Setup(options);

        var depsRoot = options.DepsFolder;
        switch (options.Platform.Target)
        {
        case TargetPlatform.Windows:
            options.OutputFiles.Add(Path.Combine(depsRoot, "SDL3.lib"));
            options.OptionalDependencyFiles.Add(Path.Combine(depsRoot, "SDL3.pdb"));
            options.OptionalDependencyFiles.Add(Path.Combine(depsRoot, "SDL3.dll"));

            // For static linkage
            options.OutputFiles.Add("Setupapi.lib");
            options.OutputFiles.Add("Version.lib");
            options.OutputFiles.Add("Imm32.lib");
            options.OutputFiles.Add("Gdi32.lib");

            break;
        case TargetPlatform.Linux:
            options.OutputFiles.Add(Path.Combine(depsRoot, "libSDL3.a"));
            options.PublicDependencies.Add("libportal");
            break;
        case TargetPlatform.Mac:
            options.OutputFiles.Add(Path.Combine(depsRoot, "libSDL3.a"));
            break;
        case TargetPlatform.Web:
            options.OutputFiles.Add("--use-port=sdl3");
            options.LinkEnv.CustomArgs.Add("-sUSE_SDL_IMAGE=0");
            options.LinkEnv.CustomArgs.Add("-sUSE_SDL_TTF=0");
            options.LinkEnv.CustomArgs.Add("-sUSE_SDL_NET=0");
            options.LinkEnv.CustomArgs.Add("-sUSE_SDL_NET=0");
            options.LinkEnv.CustomArgs.Add("-sUSE_SDL_MIXER=0");
            return;
        default: throw new InvalidPlatformException(options.Platform.Target);
        }
		
		options.PublicIncludePaths.Add(Path.Combine(Globals.EngineRoot, @"Source\ThirdParty\SDL"));
    }
}
