"use strict";

import { cleanFilePath } from "../utils/fileUtils.js";
export class DenoisingService {
  initialized = false;
  sampleRate = 0;
  constructor(api) {
    this.api = api;
  }
  getSampleRate() {
    return this.sampleRate;
  }
  isInitialized() {
    return this.initialized;
  }
  async init(config) {
    try {
      const validateResult = await this.api.validateLibraryLoaded();
      if (!validateResult.loaded) {
        return {
          success: false,
          sampleRate: 0,
          error: validateResult.status || 'Library not loaded'
        };
      }
      const cleanedConfig = {
        ...config,
        modelFile: cleanFilePath(config.modelFile)
      };
      const result = await this.api.initDenoiser(cleanedConfig);
      if (result.success) {
        this.initialized = true;
        this.sampleRate = result.sampleRate;
      }
      return result;
    } catch (error) {
      return {
        success: false,
        sampleRate: 0,
        error: error instanceof Error ? error.message : String(error)
      };
    }
  }
  async denoiseFile(filePath) {
    try {
      if (!this.initialized) {
        return {
          success: false,
          outputPath: '',
          durationMs: 0,
          error: 'Denoiser is not initialized'
        };
      }
      return await this.api.denoiseFile(cleanFilePath(filePath));
    } catch (error) {
      return {
        success: false,
        outputPath: '',
        durationMs: 0,
        error: error instanceof Error ? error.message : String(error)
      };
    }
  }
  async release() {
    try {
      const result = await this.api.releaseDenoiser();
      if (result.released) {
        this.initialized = false;
        this.sampleRate = 0;
      }
      return result;
    } catch (error) {
      console.error('Error releasing Denoising resources:', error);
      return {
        released: false
      };
    }
  }
}
//# sourceMappingURL=DenoisingService.js.map