react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
89 lines (81 loc) • 2.98 kB
text/typescript
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten.
/// Generated from rtu-ui-v2/schemas/documentdataextractor/DocumentDataExtractorUIResult.yaml
import { DocumentDataExtractionStatus } from '../../document_data_extractor/DocumentDataExtractorTypes';
import { GenericDocument } from '../../documents/GenericDocument';
import { ImageRef } from '../../imageRef/image';
import { ToJsonConfiguration } from '../../utils/json/JsonSerializationTypes';
import { DeepPartial, PartiallyConstructible } from '../../utils/utils';
/**
Configuration of the generic text scanner RTU UI result.
*/
export class DocumentDataExtractorUiResult extends PartiallyConstructible {
/**
The status of the generic text recognition step.
*/
public readonly recognitionStatus: DocumentDataExtractionStatus;
/**
Generic document containing text data. Not present, if status is FAIL.
*/
public readonly document: GenericDocument | null;
/**
Crop of the document if it was detected.
*/
public readonly croppedImage: ImageRef | null;
/** @param source {@displayType `DeepPartial<DocumentDataExtractorUiResult>`} */
public constructor(source: DeepPartial<DocumentDataExtractorUiResult> = {}) {
super();
if (source.recognitionStatus !== undefined) {
this.recognitionStatus = source.recognitionStatus;
} else {
throw new Error('recognitionStatus must be present in constructor argument');
}
if (source.document !== undefined) {
this.document = source.document != null ? new GenericDocument(source.document) : null;
} else {
throw new Error('document must be present in constructor argument');
}
if (source.croppedImage !== undefined) {
this.croppedImage = source.croppedImage != null ? ImageRef.From(source.croppedImage) : null;
} else {
throw new Error('croppedImage must be present in constructor argument');
}
}
public async serialize(
config: ToJsonConfiguration = new ToJsonConfiguration()
): Promise<DeepPartial<DocumentDataExtractorUiResult>> {
return {
recognitionStatus: this.recognitionStatus,
document: this.document != null ? await this.document.serialize(config) : null,
croppedImage: config.serializeImages
? this.croppedImage != null
? await this.croppedImage.serialize(config.imageSerializationMode)
: null
: undefined,
};
}
private _released: Boolean = false;
public release() {
if (this._released) {
return;
}
{
if (this.document != null) {
this.document.release();
}
}
{
if (this.croppedImage != null) {
this.croppedImage.release();
}
}
this._released = true;
}
public async encodeImages(): Promise<void> {
if (this.document != null) {
await this.document.encodeImages();
}
if (this.croppedImage != null) {
await this.croppedImage.encodeInPlace();
}
}
}