﻿#region Header

// Copyright (c) 2025 AccelByte Inc. All Rights Reserved.
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.

#endregion

using UnityEditor;
using UnityEngine;
using System.IO;
using BlackBox;

namespace BlackBox
{
    [InitializeOnLoad]
    public class BlackBoxConfigInstaller
    {
        static BlackBoxConfigInstaller()
        {
            EditorApplication.delayCall += Run;
        }

        private static void Run()
        {
            BlackBoxConfig config = BlackBoxConfig.Instance;
            if (config != null)
            {
                Debug.Log("Config is ready");
            }
            else
            {
                Debug.Log("Invalid configuration, generate template config");
                string directory = Path.Combine("Assets/StreamingAssets", BlackBoxConfig.BLACKBOX_DIRECTORY);

                if (!AssetDatabase.IsValidFolder(directory))
                {
                    AssetDatabase.CreateFolder("Assets/StreamingAssets", BlackBoxConfig.BLACKBOX_DIRECTORY);
                }

                ConfigIniTemplate template = new ConfigIniTemplate();
                template.Generate();

                config = BlackBoxConfig.Instance;
                Debug.Log(config != null
                    ? "Config is ready"
                    : "Template generation failed");
            }

#if UNITY_EDITOR
            BlackBoxHelperInstaller.Run();
#endif
        }
    }
}
