"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedPortGenerator = exports.RandomUniquePortGenerator = void 0;
const get_port_1 = __importDefault(require("get-port"));
class RandomPortGenerator {
    generatePort() {
        return (0, get_port_1.default)({ port: this.randomBetweenInclusive(10000, 65535) });
    }
    randomBetweenInclusive(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }
}
class RandomUniquePortGenerator {
    portGenerator;
    static assignedPorts = new Set();
    constructor(portGenerator = new RandomPortGenerator()) {
        this.portGenerator = portGenerator;
    }
    async generatePort() {
        let port;
        do {
            port = await this.portGenerator.generatePort();
        } while (RandomUniquePortGenerator.assignedPorts.has(port));
        RandomUniquePortGenerator.assignedPorts.add(port);
        return port;
    }
}
exports.RandomUniquePortGenerator = RandomUniquePortGenerator;
class FixedPortGenerator {
    ports;
    portIndex = 0;
    constructor(ports) {
        this.ports = ports;
    }
    generatePort() {
        return Promise.resolve(this.ports[this.portIndex++]);
    }
}
exports.FixedPortGenerator = FixedPortGenerator;
//# sourceMappingURL=port-generator.js.map