"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DenoisingService = void 0;
var _fileUtils = require("../utils/fileUtils.js");
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: (0, _fileUtils.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((0, _fileUtils.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
      };
    }
  }
}
exports.DenoisingService = DenoisingService;
//# sourceMappingURL=DenoisingService.js.map