"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "BambuClient", {
    enumerable: true,
    get: function() {
        return BambuClient;
    }
});
class BambuClient {
    eventEmitter2;
    settingsStore;
    logger;
    ftpAdapter;
    connected = false;
    constructor(settingsStore, loggerFactory, eventEmitter2, bambuFtpAdapter){
        this.settingsStore = settingsStore;
        this.eventEmitter2 = eventEmitter2;
        this.logger = loggerFactory(BambuClient.name);
        this.ftpAdapter = bambuFtpAdapter;
    }
    async connect(login) {
        const host = this.extractHost(login.printerURL);
        const accessCode = login.password || "";
        if (!accessCode) {
            throw new Error("Access code (password) is required for Bambu Lab printers");
        }
        this.logger.log(`Connecting to Bambu Lab printer FTP at ${host}`);
        try {
            await this.ftpAdapter.connect(host, accessCode);
            this.connected = true;
            this.logger.log("Successfully connected to Bambu Lab printer FTP");
        } catch (error) {
            this.logger.error("Failed to connect to Bambu Lab printer FTP:", error);
            await this.disconnect();
            throw error;
        }
    }
    async disconnect() {
        this.logger.log("Disconnecting from Bambu Lab printer FTP");
        await this.ftpAdapter.disconnect();
        this.connected = false;
        this.logger.log("Disconnected from Bambu Lab printer FTP");
    }
    get ftp() {
        return this.ftpAdapter;
    }
    get isConnected() {
        return this.connected && this.ftpAdapter.isConnected;
    }
    extractHost(printerURL) {
        try {
            const url = new URL(printerURL);
            return url.hostname;
        } catch  {
            return printerURL.replace(/^https?:\/\//, "").split(":")[0].split("/")[0];
        }
    }
    async getApiVersion(_login, _timeout) {
        return {
            version: "bambu-1.0"
        };
    }
}

//# sourceMappingURL=bambu.client.js.map