"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CliNodeService = void 0;
const api_client_1 = require("../api-client");
const config_storage_1 = require("../config-storage");
class CliNodeService {
    constructor(apiClient, clusterId) {
        this.apiClient = apiClient;
        this.clusterId = clusterId;
    }
    static async create(clusterId) {
        const configStorage = new config_storage_1.ConfigStorage();
        const apiUrl = configStorage.getApiUrlOrThrow();
        const apiKey = configStorage.getApiKey();
        if (!apiKey) {
            throw new Error('Not logged in. Run `flui auth login` first.');
        }
        const apiClient = new api_client_1.ApiClient({ baseUrl: apiUrl, apiKey });
        return new CliNodeService(apiClient, clusterId);
    }
    async listNodes() {
        return this.apiClient.get(`/infrastructure/clusters/${this.clusterId}/nodes`);
    }
    async addWorkers(count) {
        return this.apiClient.post(`/infrastructure/clusters/${this.clusterId}/workers`, { count });
    }
    async removeWorker(nodeId) {
        return this.apiClient.delete(`/infrastructure/clusters/${this.clusterId}/workers/${nodeId}`);
    }
    async getOperationStatus(operationId) {
        return this.apiClient.get(`/infrastructure/operations/${operationId}`);
    }
}
exports.CliNodeService = CliNodeService;
