using QuizPleaseTest.Boot.Flow;
using QuizPleaseTest.Boot.Settings;
using QuizPleaseTest.Boot.States;
using QuizPleaseTest.Boot.UI;
using QuizPleaseTest.Common.Services;
using QuizPleaseTest.Common.StateMachine;
using UnityEngine;
using VContainer;
using VContainer.Unity;

namespace QuizPleaseTest.Boot.Composition
{
    public class GameLifetimeScope : LifetimeScope
    {
        [field: SerializeField] public BootSettings BootSettings { get; private set; }
        [field: SerializeField] public SplashUIView SplashView { get; private set; }
        [field: SerializeField] public LoadingUIView LoadingView { get; private set; }
        [field: SerializeField] public MenuUIView MenuView { get; private set; }
        [field: SerializeField] public BootStatusUIView BootStatusView { get; private set; }

        protected override void Configure(IContainerBuilder builder)
        {
            builder.RegisterInstance(BootSettings);

            builder.RegisterComponent(SplashView);
            builder.RegisterComponent(LoadingView);
            builder.RegisterComponent(MenuView);
            builder.RegisterComponent(BootStatusView);

            builder.Register<BootFlowService>(Lifetime.Singleton)
                .As<IBootFlowService>()
                .As<IService>();

            builder.Register<MenuRestartSignal>(Lifetime.Singleton)
                .As<IMenuRestartSignal>();

            builder.Register<BootStatesController>(Lifetime.Singleton)
                .As<IStatesController<BootStateCode>>()
                .AsSelf();

            builder.Register<SplashState>(Lifetime.Singleton);
            builder.Register<LoadState>(Lifetime.Singleton);
            builder.Register<MenuState>(Lifetime.Singleton);

            builder.RegisterEntryPoint<BootstrapEntryPoint>();
        }
    }
}
