using UnityEngine;
using VContainer;
using VContainer.Unity;
using YachtDice.Categories;
using YachtDice.Dice;
using YachtDice.Economy;
using YachtDice.Events;
using YachtDice.Game;
using YachtDice.Inventory;
using YachtDice.Modifiers.Definition;
using YachtDice.Modifiers.Pipeline;
using YachtDice.Modifiers.Runtime;
using YachtDice.Player;
using YachtDice.Scoring;
using YachtDice.Shop;
using YachtDice.UI;

namespace YachtDice.DI
{
    public class GameLifetimeScope : LifetimeScope
    {
        [SerializeField] private ModifierCatalog modifierCatalog;
        [SerializeField] private CategoryCatalog categoryCatalog;
        [SerializeField] private DiceCatalog diceCatalog;
        [SerializeField] private ShopCatalog shopCatalog;

        [Header("Scene References")]
        [SerializeField] private ScoringSystem scoringSystem;
        [SerializeField] private CurrencyBank currencyBank;
        [SerializeField] private GameManager gameManager;
        [SerializeField] private DiceManager diceManager;
        [SerializeField] private GameController gameController;
        [SerializeField] private ShopController shopController;
        [SerializeField] private InventoryController inventoryController;

        [Header("Settings")]
        [SerializeField] private int maxActiveModifierSlots = 5;

        protected override void Configure(IContainerBuilder builder)
        {
            // SO catalogs
            builder.RegisterInstance(modifierCatalog);
            builder.RegisterInstance(categoryCatalog);
            builder.RegisterInstance(diceCatalog);
            builder.RegisterInstance(shopCatalog);

            // Core modifier services
            builder.Register<ModifierRegistry>(Lifetime.Singleton)
                .WithParameter<int>(maxActiveModifierSlots);
            builder.Register<ModifierPipeline>(Lifetime.Singleton);
            builder.Register<GameEventBus>(Lifetime.Singleton);

            // Player subsystems
            builder.Register<DiceCollection>(Lifetime.Singleton);
            builder.Register<InventoryModel>(Lifetime.Singleton);

            // Unified player model
            builder.Register<PlayerModel>(Lifetime.Singleton);

            // Shop
            builder.Register<ShopModel>(Lifetime.Singleton);

            // Scene MonoBehaviour components
            builder.RegisterComponent(scoringSystem);
            builder.RegisterComponent(currencyBank);
            builder.RegisterComponent(gameManager);
            builder.RegisterComponent(diceManager);
            builder.RegisterComponent(gameController);
            builder.RegisterComponent(shopController);
            builder.RegisterComponent(inventoryController);
        }
    }
}
