// Copyright 2012-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Adapted from server/events.go (client.sendInternalMsg) in the NATS server Go source.

namespace ZB.MOM.NatsNet.Server;

public sealed partial class ClientConnection
{
    // =========================================================================
    // Group E: sendInternalMsg from a client context
    // =========================================================================

    /// <summary>
    /// Sends an internal message from this client's context, avoiding no-echo issues
    /// when the message originates from a non-system client.
    /// Mirrors Go <c>(c *client) sendInternalMsg(...)</c> in server/events.go.
    /// </summary>
    internal void SendInternalMsg(
        string      subject,
        string      reply,
        ServerInfo? si,
        object?     msg)
    {
        var srv = Server as NatsServer;
        if (srv is null) return;

        srv.SendInternalMsgFromClient(this, subject, reply, si, msg);
    }
}
