import { BarcodeFormat } from '../barcode/BarcodeRecognizerConfiguration';
import { DeepPartial, PartiallyConstructible } from '../../utils';
import { GenericDocument } from '../../documents/GenericDocument';

/**
Data about the scanned barcode.
*/
export class BarcodeItem extends PartiallyConstructible {
  /**
    Recognized barcode symbology.
    */
  public readonly type: BarcodeFormat | null;
  /**
    Number of recognized barcodes of this symbology and value.
    */
  public readonly count: number;
  /**
    Recognized value of the barcode.
    */
  public readonly text: string;
  /**
    Recognized barcode value with extension (if available).
    */
  public readonly textWithExtension: string;
  /**
    Representation of the raw data that is contained the recognized barcode.
    */
  public readonly rawBytes: string;
  /**
    The parsed known document format (if parsed successfully).
    */
  public readonly parsedDocument: GenericDocument | null;

  /** @param source {@displayType `DeepPartial<BarcodeItem>`} */
  public constructor(source: DeepPartial<BarcodeItem> = {}) {
    super();
    if (source.type !== undefined) {
      this.type = source.type != null ? source.type : null;
    } else {
      throw new Error('type must be present in constructor argument');
    }
    if (source.count !== undefined) {
      this.count = source.count;
    } else {
      throw new Error('count must be present in constructor argument');
    }
    if (source.text !== undefined) {
      this.text = source.text;
    } else {
      throw new Error('text must be present in constructor argument');
    }
    if (source.textWithExtension !== undefined) {
      this.textWithExtension = source.textWithExtension;
    } else {
      throw new Error('textWithExtension must be present in constructor argument');
    }
    if (source.rawBytes !== undefined) {
      this.rawBytes = source.rawBytes;
    } else {
      throw new Error('rawBytes must be present in constructor argument');
    }
    if (source.parsedDocument !== undefined) {
      this.parsedDocument =
        source.parsedDocument != null ? new GenericDocument(source.parsedDocument) : null;
    } else {
      throw new Error('parsedDocument must be present in constructor argument');
    }
  }
}
