"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "OctoprintApi", {
    enumerable: true,
    get: function() {
        return OctoprintApi;
    }
});
const _printerapiinterface = require("./printer-api.interface");
const _runtimeexceptions = require("../exceptions/runtime.exceptions");
class OctoprintApi {
    client;
    printerLogin;
    constructor({ octoprintClient, printerLogin }){
        this.client = octoprintClient;
        this.printerLogin = printerLogin;
    }
    get type() {
        return _printerapiinterface.OctoprintType;
    }
    set login(login) {
        this.printerLogin = login;
    }
    get login() {
        return this.printerLogin;
    }
    async getVersion() {
        const result = await this.client.getApiVersion(this.login);
        return result.data?.server;
    }
    async connect() {
        await this.client.sendConnectionCommand(this.login, this.client.connectCommand);
    }
    async disconnect() {
        await this.client.sendConnectionCommand(this.login, this.client.disconnectCommand);
    }
    async restartServer() {
        await this.client.postServerRestartCommand(this.login);
    }
    async restartHost() {
        throw new _runtimeexceptions.NotImplementedException();
    }
    async restartPrinterFirmware() {
        throw new _runtimeexceptions.NotImplementedException();
    }
    async startPrint(path) {
        await this.client.postSelectPrintFile(this.login, path, true);
    }
    async pausePrint() {
        await this.client.sendJobCommand(this.login, this.client.pauseJobCommand);
    }
    async resumePrint() {
        await this.client.sendJobCommand(this.login, this.client.resumeJobCommand);
    }
    async cancelPrint() {
        await this.client.sendJobCommand(this.login, this.client.cancelJobCommand);
    }
    async sendGcode(script) {
        await this.client.sendCustomGCodeCommand(this.login, script);
    }
    async quickStop() {
        await this.client.sendCustomGCodeCommand(this.login, "M112");
    }
    async movePrintHead(amounts) {
        await this.client.sendPrintHeadJogCommand(this.login, amounts);
    }
    async homeAxes(axes) {
        await this.client.sendPrintHeadHomeCommand(this.login, axes);
    }
    async getFiles() {
        const files = await this.client.getLocalFiles(this.login, false);
        return files.map((f)=>({
                path: f.path,
                size: f.size,
                date: f.date
            }));
    }
    async downloadFile(path) {
        return await this.client.downloadFile(this.login, path);
    }
    async uploadFile(fileOrBuffer, uploadToken) {
        await this.client.uploadFileAsMultiPart(this.login, fileOrBuffer, {
            select: true,
            print: true
        }, uploadToken);
    }
    async deleteFile(path) {
        await this.client.deleteFileOrFolder(this.login, path);
    }
    async deleteFolder(path) {
        await this.client.deleteFileOrFolder(this.login, path);
    }
    async getSettings() {
        return await this.client.getSettings(this.login);
    }
    async getReprintState() {
        const connected = await this.client.getConnection(this.login);
        const connectionState = connected.current?.state;
        const selectedJob = await this.client.getJob(this.login);
        const currentJobFile = selectedJob?.job?.file;
        if (!currentJobFile?.name) {
            return {
                connectionState,
                reprintState: _printerapiinterface.ReprintState.NoLastPrint
            };
        }
        return {
            connectionState,
            file: currentJobFile,
            reprintState: _printerapiinterface.ReprintState.LastPrintReady
        };
    }
}

//# sourceMappingURL=octoprint.api.js.map