using System.Collections;
using MadByteLabs.ValidationGame.Core;
using MadByteLabs.ValidationGame.Data;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public sealed class BootstrapperTests
{
    [Test]
    public void PauseNotifiesOnlyOnStateChanges()
    {
        var data = new SessionData();
        int calls = 0;
        data.PauseChanged += paused => calls++;
        data.SetPaused(false);
        data.SetPaused(true);
        data.SetPaused(true);
        data.SetPaused(false);
        Assert.AreEqual(2, calls);
        Assert.IsFalse(data.IsPaused);
    }
    [UnityTest]
    public IEnumerator BootstrapperCanRestartAfterDestruction()
    {
        var first = new GameObject("First bootstrap");
        first.AddComponent<MonoBootstrapper>();
        yield return null;
        Object.Destroy(first);
        yield return null;
        var second = new GameObject("Second bootstrap");
        MonoBootstrapper bootstrapper = second.AddComponent<MonoBootstrapper>();
        yield return null;
        Assert.IsTrue(bootstrapper.enabled);
        Object.Destroy(second);
        yield return null;
        LogAssert.NoUnexpectedReceived();
    }
    [UnityTest]
    public IEnumerator DuplicateDoesNotReplaceOwner()
    {
        var owner = new GameObject("Owner");
        MonoBootstrapper bootstrapper = owner.AddComponent<MonoBootstrapper>();
        var duplicate = new GameObject("Duplicate");
        LogAssert.Expect(LogType.Error,
            "A product bootstrapper is already running. Removing the duplicate component.");
        duplicate.AddComponent<MonoBootstrapper>();
        yield return null;
        Assert.IsTrue(bootstrapper.enabled);
        Assert.IsNull(duplicate.GetComponent<MonoBootstrapper>());
        Object.Destroy(owner);
        Object.Destroy(duplicate);
        yield return null;
    }
}
