using NUnit.Framework;
using SVSim.BattleEngine.Rng;
using Wizard.BattleMgr;

namespace SVSim.BattleEngine.Tests
{
    // M13 step 1 (the M2 ConstructionProbe pattern): can a NetworkBattleManagerBase-derived mgr be
    // built headless at all? NetworkBattleManagerSetup constructs NetworkTouchControl(this,
    // _battleCamera, _backGround) + RegisterActionManager + OperateReceive — the largest new shim
    // surface since M5's prefab path. Isolate "ctor runs" before any play is driven.
    [TestFixture]
    public class NetworkMgrConstructionProbeTests : NetworkEmitFixtureBase
    {
        private TestBattleScope _scope;

        [SetUp] public void SetUpScope() { _scope = new TestBattleScope(); }
        [TearDown] public void TearDownScope() { _scope?.Dispose(); _scope = null; }

        [Test]
        public void HeadlessNetworkBattleMgr_constructs_headless()
        {
            Assert.DoesNotThrow(() =>
            {
                var mgr = new HeadlessNetworkBattleMgr(new HeadlessContentsCreator());
                _scope.Ctx.Mgr = mgr;
                Assert.That(mgr, Is.Not.Null);
            });
        }

        [Test]
        public void OnEmit_capture_seam_is_wired_via_injected_agent()
        {
            var (mgr, emitted) = HeadlessEngineEnv.NewNetworkEmitBattle();
            _scope.Ctx.Mgr = mgr;
            Assert.That(mgr, Is.Not.Null);
            Assert.That(Wizard.ToolboxGame.RealTimeNetworkAgent, Is.Not.Null,
                "agent must be injected so NetworkBattleSender's ToolboxGame.RealTimeNetworkAgent.* calls resolve");
            Assert.That(emitted, Is.Empty, "no emit yet — only the seam is wired");
        }
    }
}
