import * as net from 'node:net';
import { WrappedSocket } from './wrapped-socket.js';

/**
 * Type guard to check if a socket is a WrappedSocket
 */
export function isWrappedSocket(socket: net.Socket | WrappedSocket): socket is WrappedSocket {
  return socket instanceof WrappedSocket || 'socket' in socket;
}

/**
 * Helper to get the underlying socket from either a Socket or WrappedSocket
 */
export function getUnderlyingSocket(socket: net.Socket | WrappedSocket): net.Socket {
  return isWrappedSocket(socket) ? socket.socket : socket;
}

/**
 * Type that represents either a regular socket or a wrapped socket
 */
export type AnySocket = net.Socket | WrappedSocket;