#nullable enable
using System.Threading;
using System.Threading.Tasks;

namespace IGP.UnitySDK.Abstractions
{
    /// <summary>
    /// Engine adapter extension contract. Implementations are discovered on the
    /// same GameObject as <see cref="IGPRuntimeManager"/>.
    /// </summary>
    public interface IIGPRuntimeExtension
    {
        int InitializationOrder { get; }

        Task<bool> InitializeAsync(
            IIGPRuntimeContext context,
            CancellationToken cancellationToken = default);

        Task ShutdownAsync(CancellationToken cancellationToken = default);
    }

    /// <summary>
    /// Core runtime services available to optional Unity SDK packages.
    /// </summary>
    public interface IIGPRuntimeContext
    {
        IGPConfig? Config { get; }
        bool IsInitialized { get; }
        CancellationToken LifetimeToken { get; }
        IIGPHostCommandGateway Host { get; }

        /// <summary>
        /// Raised when the active Host platform reports that a fresh Multiplayer
        /// bootstrap may be requested.
        /// </summary>
        event System.Action? MultiplayerBootstrapAvailable;

        /// <summary>
        /// Requests a fresh immutable Gateway snapshot and RoomNode descriptor
        /// from the provider implemented by the active Host platform runtime.
        /// </summary>
        Task<IGPMultiplayerBootstrap?> RequestMultiplayerBootstrapAsync(
            CancellationToken cancellationToken = default);
    }
}
