"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PunctuationService = void 0;
var _fileUtils = require("../utils/fileUtils.js");
class PunctuationService {
  initialized = false;
  constructor(api) {
    this.api = api;
  }
  validateLibrary() {
    return this.api.validateLibraryLoaded();
  }
  async init(config) {
    try {
      const validateResult = await this.validateLibrary();
      if (!validateResult.loaded) {
        return {
          success: false,
          error: validateResult.status || 'Library not loaded'
        };
      }
      const nativeConfig = {
        modelDir: (0, _fileUtils.cleanFilePath)(config.modelDir),
        cnnBilstm: config.cnnBilstm,
        bpeVocab: config.bpeVocab,
        numThreads: config.numThreads ?? 1,
        debug: config.debug ?? false,
        provider: config.provider ?? 'cpu',
        ...(config.modelBaseUrl && {
          modelBaseUrl: config.modelBaseUrl
        }),
        ...(config.onProgress && {
          onProgress: config.onProgress
        })
      };
      const result = await this.api.initPunctuation(nativeConfig);
      if (result.success) {
        this.initialized = true;
      }
      return result;
    } catch (error) {
      return {
        success: false,
        error: error instanceof Error ? error.message : String(error)
      };
    }
  }
  async addPunctuation(text) {
    try {
      if (!this.initialized) {
        return {
          success: false,
          text: '',
          durationMs: 0,
          error: 'Punctuation is not initialized'
        };
      }
      return await this.api.addPunctuation(text);
    } catch (error) {
      return {
        success: false,
        text: '',
        durationMs: 0,
        error: error instanceof Error ? error.message : String(error)
      };
    }
  }
  async release() {
    try {
      const result = await this.api.releasePunctuation();
      if (result.released) {
        this.initialized = false;
      }
      return result;
    } catch (error) {
      console.error('Error releasing Punctuation resources:', error);
      return {
        released: false
      };
    }
  }
}
exports.PunctuationService = PunctuationService;
//# sourceMappingURL=PunctuationService.js.map