#nullable enable
using System;

namespace IGP.UnitySDK
{
    /// <summary>
    /// Host-integration entry point for forwarding Mobile Host Session frames
    /// between an embedded Unity runtime and its native application shell.
    /// </summary>
    public sealed class IGPMobileHostSessionIntegration
    {
        private readonly IGPMobileHostSessionBridge bridge;

        internal IGPMobileHostSessionIntegration(IGPMobileHostSessionBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));
        }

        /// <summary>
        /// Sets the callback used to forward Unity frames to the mobile host.
        /// Pass <c>null</c> when the host view is no longer bound.
        /// </summary>
        public void SetFrameSender(Action<string>? sender)
        {
            bridge.SetFrameSender(sender);
        }

        /// <summary>
        /// Marks the host-side channel ready for a Mobile Host Session attach.
        /// </summary>
        public void MarkReady()
        {
            bridge.MarkReady();
        }

        /// <summary>
        /// Forwards a carrier JSON frame received from the mobile host to Core.
        /// </summary>
        public void ReceiveFrame(string frameJson)
        {
            bridge.ReceiveFrame(frameJson);
        }

        /// <summary>
        /// Closes the current channel and wakes pending readiness waits.
        /// </summary>
        public void Close(string reason = "mobile-host-session-closed")
        {
            bridge.Close(reason);
        }
    }
}
