/** 
*   Docutain SDK React Native
*   Copyright (c) INFOSOFT Informations- und Dokumentationssysteme GmbH. All rights reserved.
*
*   Docutain SDK React Native is a commercial product and requires a license. 
*   Details found in the LICENSE file in the root directory of this source tree.
*/

import { NativeModules, Platform } from 'react-native';

import type {PageEditConfiguration, DocumentScannerConfiguration, AnalyzeConfiguration, DocutainButton, ButtonConfiguration, TextConfiguration} from './model';
import type {PDFPageFormat, LogLevel, ScanFilter, Source, PageSourceType} from './model';
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';

export {PageEditConfiguration, DocumentScannerConfiguration, AnalyzeConfiguration, PDFPageFormat, LogLevel, ScanFilter, Source, PageSourceType, DocutainButton, ButtonConfiguration, TextConfiguration};

const LINKING_ERROR =
  `The package 'react-native-docutain-sdk' doesn't seem to be linked. Make sure: \n\n` +
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
  '- You rebuilt the app after installing the package\n' +
  '- You are not using Expo Go\n';

 /**
 * Main class of the Docutain SDK.
 */
export interface DocutainSDK {    
  /**
  * Initializes the Docutain SDK.
  * This method needs to be called prior to using any functionality of the Docutain SDK.
  * @param licenseKey your Docutain SDK license key.
  * @return true if initialization was successful, false otherwise. Use getLastError() to retrieve error message.
  */
  initSDK(licenseKey: string): Promise<boolean> 
  /**
  * Starts the document scanner.
  * @param options an instance of @see {@link DocumentScannerConfiguration}.
  * @return true if user finished scan process successfully, false if user canceled the scan process.
  */
  scanDocument(options: DocumentScannerConfiguration): Promise<boolean>;
  /**
   * Loads a file from the given path.
   * @param filePath the path pointing to the file to be loaded.
   * @return true if load was succesful, false otherwise.
   */
  loadFile(filePath: string): Promise<boolean>;
   /**
   * Detects the text of the currently loaded document and returns it.
   *
   * @return the detected text
   */
  getText(): Promise<string>;
  /**
   * Detects the text of the currently loaded document and returns it.
   *
   * @param pageNumber number of the page you want the text from or leave empty to get text of entire document
   * @return the detected text
   */
  getTextPage(pageNumber: Int32): Promise<string>;
  /**
   * This method sets the analyze configuration.
   *
   * @param analyzeConfiguration An instance of AnalyzeConfiguration.
   * @return true if configuration was successful, false otherwise.
   */
  setAnalyzeConfiguration(config: AnalyzeConfiguration): Promise<boolean>;
   /**
   * Analyzes the currently loaded document and returns the detected data.
   *
   * @return the detected data as JSON String
   */
  analyze(): Promise<string>;
   /**
   * This method generates a PDF document from the loaded or scanned pages.
   *
   * @param filePath the file path where to save the PDF document.
   * @param overwrite if file already exist, indicate whether to override it or to append number, e.g. TestPDF(1).pdf.
   * @param PDF_PageFormat the PDF page format, refer to PDFPageFormat.
   * @return the file path if PDF document was generated successfully, null otherwise.
   */
  writePDF(filePath: string, overWrite: boolean, PDF_PageFormat: PDFPageFormat): Promise<string>;
  /**
   * This method returns the latest error message, if any error occurred.
   *
   * @return the error message.
   */
  getLastError(): Promise<string>;
  /**
   * This method sets the log level, which determines the severity of the message.
   *
   * @param logLevel The Level determining which kind of messages should be logged. The default is Level.VERBOSE.
   *
   */
  setLogLevel(logLevel: LogLevel): Promise<boolean>;
   /**
   * This method returns the Trace file which includes logging and error messages.
   *
   * @return the path to the Trace file.
   */
  getTraceFile(): Promise<string>;
  /**
   * This method deletes all temporary files created by the Docutain SDK.
   *
   * @param deleteTraceFileContent If true, the content of the Trace file which you can send us in order to solve any problems will also be deleted
   *
   * @return true if all files deleted successfully, false if an error occurred
   */
  deleteTempFiles(deleteTraceFileContent: boolean): Promise<boolean>;
  /**
   * This method generates a JPG from the loaded or scanned page and saves it to a local file.
   *
   * @param pageNumber the page to be generated as JPG
   * @param filePath the file path where to save the JPG file
   * @return the file path if JPG was generated successfully, null otherwise
   */
  writeImage(pageNumber: Int32, filePath: string): Promise<string>;
   /**
   * This method generates a JPG from the loaded or scanned page and returns it as a base64 encoded string.
   *
   * @param pageNumber the page to be generated as JPG
   * @param pageSourceType the PageSourceType type to be used when generating the JPG
   * @return the base64 encoded string if JPG was generated successfully, null otherwise
   */
  getImageBytes(pageNumber: Int32, pageSourceType: PageSourceType): Promise<string>;
  /**
   * This method returns the page count of the currently loaded document.
   *
   * @return page count of the currently loaded document.
   */
  pageCount(): Promise<Int32>;
}

const DocutainSDK: DocutainSDK = NativeModules.DocutainSdk
 ? NativeModules.DocutainSdk
 : new Proxy(
     {},
     {
       get() {
         throw new Error(LINKING_ERROR);
       },
     }
   );


export default DocutainSDK;
