"use strict";
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//
Object.defineProperty(exports, "__esModule", { value: true });
exports.ForwardedPort = void 0;
/**
 * Represents a port being forwarded over an SSH session.
 */
class ForwardedPort {
    /** @internal */
    constructor(localPort, remotePort, isRemote) {
        if (localPort === null && remotePort === null) {
            throw new TypeError('Local and remote ports cannot both be null.');
        }
        else if (!isRemote && remotePort === null) {
            // The remote port number should always be known for locally forwarded ports.
            throw new TypeError('The report port number must not be null for locally forwarded ports.');
        }
        if (localPort !== null && (typeof localPort !== 'number' || localPort <= 0)) {
            throw new TypeError('Local port must be a positive integer.');
        }
        else if (remotePort !== null && (typeof remotePort !== 'number' || remotePort <= 0)) {
            throw new TypeError('Remote port must be a positive integer: ' + remotePort);
        }
        this.localPort = localPort;
        this.remotePort = remotePort;
        // The string representation is constructed ahead of time because it is used as a workaround
        // for JavaScript Map<T> objects not supporting custom object equality. The string
        // representation is used as the map key.
        const arrow = isRemote ? '->' : '<-';
        if (this.localPort === null) {
            this.str = `${arrow}${this.remotePort}`;
        }
        else if (this.remotePort == null) {
            this.str = `${this.localPort}${arrow}`;
        }
        else {
            this.str = `${this.localPort}${arrow}${this.remotePort}`;
        }
    }
    /**
     * Gets a string representation of the forwarded port, which includes both
     * local and remote port numbers if present.
     *
     * An arrow shows the direction of connections (channel open requests).
     * Once connections are opened, data may flow in both directions.
     */
    toString() {
        return this.str;
    }
}
exports.ForwardedPort = ForwardedPort;
//# sourceMappingURL=https://github.com/VSCodium/sourcemaps/releases/download/stable-824c4c46a288b839f13b24022655329c2aeb9f81/node_modules-@microsoft-dev-tunnels-ssh-tcp-events-forwardedPort.js.map