"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackupClient = void 0;
const api_client_1 = require("./api-client");
const config_storage_1 = require("./config-storage");
class BackupClient {
    constructor(api) {
        this.api = api;
    }
    static fromConfig() {
        const cfg = new config_storage_1.ConfigStorage();
        const apiUrl = cfg.getApiUrlOrThrow();
        const apiKey = cfg.getApiKey();
        if (!apiKey) {
            throw new Error('Not logged in. Run `flui auth login` first or check API key.');
        }
        return new BackupClient(new api_client_1.ApiClient({ baseUrl: apiUrl, apiKey }));
    }
    // ─── Destinations ────────────────────────────────────────────────────────
    async listDestinations() {
        return this.api.get('/backup-destinations');
    }
    async getDestination(id) {
        return this.api.get(`/backup-destinations/${id}`);
    }
    async createDestination(input) {
        return this.api.post('/backup-destinations', input);
    }
    async testDestination(id) {
        return this.api.post(`/backup-destinations/${id}/test`);
    }
    async refreshDestinationUsage(id) {
        return this.api.post(`/backup-destinations/${id}/refresh-usage`);
    }
    async deleteDestination(id) {
        return this.api.delete(`/backup-destinations/${id}`);
    }
    // ─── Policies ────────────────────────────────────────────────────────────
    async listPolicies() {
        return this.api.get('/backup-policies');
    }
    async listPoliciesForCluster(clusterId) {
        return this.api.get(`/backup-policies/cluster/${clusterId}`);
    }
    async getPolicy(id) {
        return this.api.get(`/backup-policies/${id}`);
    }
    async createPolicy(input) {
        return this.api.post('/backup-policies', input);
    }
    async deletePolicy(id) {
        return this.api.delete(`/backup-policies/${id}`);
    }
    // ─── Jobs ────────────────────────────────────────────────────────────────
    async runJobForPolicy(policyId) {
        return this.api.post('/backup-jobs', { policyId });
    }
    async getJob(id) {
        return this.api.get(`/backup-jobs/${id}`);
    }
    async listJobsForCluster(clusterId) {
        return this.api.get(`/backup-jobs/cluster/${clusterId}`);
    }
    // ─── Restore ─────────────────────────────────────────────────────────────
    async previewRestore(input) {
        return this.api.post('/restore-jobs/preview', input);
    }
    async createRestore(input) {
        return this.api.post('/restore-jobs', input);
    }
    async listRestores() {
        return this.api.get('/restore-jobs');
    }
    async getRestore(id) {
        return this.api.get(`/restore-jobs/${id}`);
    }
}
exports.BackupClient = BackupClient;
