using System.Diagnostics;

namespace Metin2Launcher.Runtime;

/// <summary>
/// STUB. Windows shared-memory delivery for the runtime key is not implemented
/// yet — the receiver on the client side has not landed. This type exists so
/// the factory wiring in <see cref="Program"/> and the docs have a concrete
/// name to reference, and so a future change can fill in the body without
/// churning callers.
///
/// Planned implementation:
///   1. Create a named, write-only <c>MemoryMappedFile</c> with a random suffix
///      (e.g. <c>m2pack-key-&lt;guid&gt;</c>) and a <c>NamedPipeServerStream</c>-style
///      ACL that only grants access to the child PID once it has been spawned.
///   2. Write a short binary header (magic, key_id length, key_id, master_key,
///      sign_pubkey) into the mapping.
///   3. Set an env var on the child with the mapping name so the receiver can
///      <c>OpenExisting</c> and read the key before zeroing the source.
///   4. Zero and close the mapping from the launcher side once the child
///      signals it has consumed the key (via <c>ClientAppliedReporter</c>).
///
/// Until then, calling <see cref="Apply"/> throws — the factory must never
/// select this delivery on a non-Windows host, and on Windows the code path
/// is guarded behind a feature flag that is off by default.
/// </summary>
public sealed class SharedMemoryKeyDelivery : IRuntimeKeyDelivery
{
    public string Name => "shared-memory";

    public void Apply(ProcessStartInfo psi, RuntimeKey key)
    {
        // TODO(m2pack): implement Windows shared-memory delivery once the
        // client-side receiver is in place. Tracked in docs/m2pack-integration.md.
        throw new NotSupportedException(
            "shared-memory runtime key delivery is not implemented yet; " +
            "use EnvVarKeyDelivery for the MVP.");
    }
}
