using UnityEngine;
using EventsAppQuest.Application.Services;

namespace EventsAppQuest.Core
{
    /// <summary>
    /// Ponto de entrada da aplicacao; inicializa configuracao e servicos.
    /// Anexar a um GameObject na cena inicial (Bootstrap).
    /// </summary>
    public class AppBootstrap : MonoBehaviour
    {
        [SerializeField] private AppConfig _appConfig;

        private void Awake()
        {
            if (_appConfig == null)
            {
                Debug.LogError("[AppBootstrap] AppConfig is not assigned.");
                return;
            }

            var registry = ServiceRegistry.Instance;

            if (_appConfig.UseMockServices)
                registry.RegisterMockServices();

            var router = new SceneRouter();
            registry.Register<SceneRouter>(router);
            registry.Register<AppSession>(new AppSession());

            Debug.Log("[AppBootstrap] Services initialized.");

            if (_appConfig.OpenQuestPresentationOnStartup)
            {
                router.LoadQuestPresentationScene();
            }
            else if (!string.IsNullOrEmpty(_appConfig.MainSceneName))
            {
                router.LoadScene(_appConfig.MainSceneName);
            }
        }
    }
}
