import { BackgroundStyle } from '../common/Common';
import { DeepPartial, PartiallyConstructible } from '../../utils';
import { BadgeStyle } from '../common/Common';
import { PolygonStyle } from '../common/Common';
import { StyledText } from '../common/Common';

/**
Configuration of the overlay polygon displayed on top of a barcode in the camera preview.
*/
export class ArOverlayPolygonConfiguration extends PartiallyConstructible {
  /**
    Control the visibility of the overlay polygon.
    Default is true
    */
  public visible: boolean = true;
  /**
    Appearance of the overlay polygon when a barcode is not selected.
    */
  public deselected: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorSurface',
    fillColor: '#00000000',
    strokeWidth: 2.0,
    cornerRadius: 2.0,
  });
  /**
    Appearance of the overlay polygon after a barcode has been selected.
    */
  public selected: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorPositive',
    fillColor: '#00000000',
    strokeWidth: 2.0,
    cornerRadius: 2.0,
  });

  /** @param source {@displayType `DeepPartial<ArOverlayPolygonConfiguration>`} */
  public constructor(source: DeepPartial<ArOverlayPolygonConfiguration> = {}) {
    super();
    if (source.visible !== undefined) {
      this.visible = source.visible;
    }
    if (source.deselected !== undefined) {
      this.deselected = new PolygonStyle(source.deselected);
    }
    if (source.selected !== undefined) {
      this.selected = new PolygonStyle(source.selected);
    }
  }
}

/**
Where to display the barcode info box in the camera preview.

- `DISABLED`:
   Don't display any barcode info.
- `STACKED`:
   Display the barcode info box in the center of the overlay polygon.
- `BELOW`:
   Display the barcode info box below the overlay polygon.
- `ABOVE`:
   Display the barcode info box above the overlay polygon.
*/
export type BarcodeItemInfoPosition = 'DISABLED' | 'STACKED' | 'BELOW' | 'ABOVE';

/**
Configuration of the barcode info box displayed in the camera preview.
*/
export class BarcodeItemConfiguration extends PartiallyConstructible {
  /**
    Control the visibility of the barcode image in the info box.
    Default is true
    */
  public imageVisible: boolean = true;
  /**
    Configuration of the text displaying a barcode's value in the info box when the barcode has been selected.
    */
  public titleSelected: StyledText = new StyledText({
    text: 'BARCODE_TITLE',
    color: '?sbColorOnSurface',
  });
  /**
    Configuration of the text displaying a barcode's symbology in the info box when the barcode has been selected.
    */
  public subtitleSelected: StyledText = new StyledText({
    text: 'BARCODE_SUBTITLE',
    color: '?sbColorOnSurfaceVariant',
  });
  /**
    Configuration of the text displaying a barcode's value in the info box when the barcode is yet to be selected.
    */
  public titleDeselected: StyledText = new StyledText({
    text: 'BARCODE_TITLE',
    color: '?sbColorOnSurface',
  });
  /**
    Configuration of the text displaying a barcode's symbology in the info box when the barcode is yet to be selected.
    */
  public subtitleDeselected: StyledText = new StyledText({
    text: 'BARCODE_SUBTITLE',
    color: '?sbColorOnSurfaceVariant',
  });
  /**
    Appearance of the barcode info box's background when a barcode has been selected.
    */
  public backgroundSelected: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorPositive',
    fillColor: '?sbColorPositive',
    strokeWidth: 0.0,
    cornerRadius: 10.0,
  });
  /**
    Appearance of the barcode info box's background when a barcode is yet to be selected.
    */
  public backgroundDeselected: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorSurface',
    fillColor: '?sbColorSurface',
    strokeWidth: 0.0,
    cornerRadius: 10.0,
  });

  /** @param source {@displayType `DeepPartial<BarcodeItemConfiguration>`} */
  public constructor(source: DeepPartial<BarcodeItemConfiguration> = {}) {
    super();
    if (source.imageVisible !== undefined) {
      this.imageVisible = source.imageVisible;
    }
    if (source.titleSelected !== undefined) {
      this.titleSelected = new StyledText(source.titleSelected);
    }
    if (source.subtitleSelected !== undefined) {
      this.subtitleSelected = new StyledText(source.subtitleSelected);
    }
    if (source.titleDeselected !== undefined) {
      this.titleDeselected = new StyledText(source.titleDeselected);
    }
    if (source.subtitleDeselected !== undefined) {
      this.subtitleDeselected = new StyledText(source.subtitleDeselected);
    }
    if (source.backgroundSelected !== undefined) {
      this.backgroundSelected = new PolygonStyle(source.backgroundSelected);
    }
    if (source.backgroundDeselected !== undefined) {
      this.backgroundDeselected = new PolygonStyle(source.backgroundDeselected);
    }
  }
}

/**
Configuration of the AR overlay displayed on top of barcodes in the camera preview.
*/
export class ArOverlayGeneralConfiguration extends PartiallyConstructible {
  /**
    Control the visibility of the user guidance.
    Default is false
    */
  public visible: boolean = false;
  /**
    Parameters of the counter badge appearance e.g. color of background its stroke and text/icon color.
    */
  public counterBadge: BadgeStyle = new BadgeStyle({
    background: new BackgroundStyle({}),
    foregroundColor: '?sbColorOnSurface',
  });
  /**
    If enabled, the scanner will always immediately scan a barcode in the viewfinder or the camera view. The overlay will mark the scanned barcodes and stays above them.
    Default is false
    */
  public automaticSelectionEnabled: boolean = false;
  /**
    Where to display the barcode info box in the camera preview.
    Default is BELOW
    */
  public barcodeItemInfoPosition: BarcodeItemInfoPosition = 'BELOW';
  /**
    Configuration of the overlay polygon displayed on top of a barcode in the camera preview.
    */
  public polygon: ArOverlayPolygonConfiguration = new ArOverlayPolygonConfiguration({
    visible: true,
    deselected: new PolygonStyle({}),
    selected: new PolygonStyle({}),
  });
  /**
    Configuration of the barcode info box displayed in the camera preview.
    */
  public barcodeItemConfiguration: BarcodeItemConfiguration = new BarcodeItemConfiguration({
    imageVisible: true,
    titleSelected: new StyledText({ text: 'BARCODE_TITLE', color: '?sbColorOnSurface' }),
    subtitleSelected: new StyledText({
      text: 'BARCODE_SUBTITLE',
      color: '?sbColorOnSurfaceVariant',
    }),
    titleDeselected: new StyledText({ text: 'BARCODE_TITLE', color: '?sbColorOnSurface' }),
    subtitleDeselected: new StyledText({
      text: 'BARCODE_SUBTITLE',
      color: '?sbColorOnSurfaceVariant',
    }),
    backgroundSelected: new PolygonStyle({
      strokeColor: '?sbColorPositive',
      fillColor: '?sbColorPositive',
      strokeWidth: 1.0,
      cornerRadius: 5.0,
    }),
    backgroundDeselected: new PolygonStyle({
      strokeColor: '?sbColorSurface',
      fillColor: '?sbColorSurface',
      strokeWidth: 1.0,
      cornerRadius: 5.0,
    }),
  });

  /** @param source {@displayType `DeepPartial<ArOverlayGeneralConfiguration>`} */
  public constructor(source: DeepPartial<ArOverlayGeneralConfiguration> = {}) {
    super();
    if (source.visible !== undefined) {
      this.visible = source.visible;
    }
    if (source.counterBadge !== undefined) {
      this.counterBadge = new BadgeStyle(source.counterBadge);
    }
    if (source.automaticSelectionEnabled !== undefined) {
      this.automaticSelectionEnabled = source.automaticSelectionEnabled;
    }
    if (source.barcodeItemInfoPosition !== undefined) {
      this.barcodeItemInfoPosition = source.barcodeItemInfoPosition;
    }
    if (source.polygon !== undefined) {
      this.polygon = new ArOverlayPolygonConfiguration(source.polygon);
    }
    if (source.barcodeItemConfiguration !== undefined) {
      this.barcodeItemConfiguration = new BarcodeItemConfiguration(source.barcodeItemConfiguration);
    }
  }
}

/**
Configuration of the overlay polygon displayed on top of a barcode in the camera preview.
*/
export class FindAndPickArOverlayPolygonConfiguration extends PartiallyConstructible {
  /**
    Control the visibility of the overlay polygon.
    Default is true
    */
  public visible: boolean = true;
  /**
    Appearance of the overlay polygon when a barcode is partially scanned.
    */
  public partiallyScanned: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorWarning',
    fillColor: '#00000000',
    strokeWidth: 3.0,
    cornerRadius: 5.0,
  });
  /**
    Appearance of the overlay polygon when a barcode is rejected.
    */
  public rejected: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorSurface',
    fillColor: '#00000000',
    strokeWidth: 3.0,
    cornerRadius: 5.0,
  });
  /**
    Appearance of the overlay polygon when a barcode is completed.
    */
  public completed: PolygonStyle = new PolygonStyle({
    strokeColor: '?sbColorPositive',
    fillColor: '#00000000',
    strokeWidth: 3.0,
    cornerRadius: 5.0,
  });

  /** @param source {@displayType `DeepPartial<FindAndPickArOverlayPolygonConfiguration>`} */
  public constructor(source: DeepPartial<FindAndPickArOverlayPolygonConfiguration> = {}) {
    super();
    if (source.visible !== undefined) {
      this.visible = source.visible;
    }
    if (source.partiallyScanned !== undefined) {
      this.partiallyScanned = new PolygonStyle(source.partiallyScanned);
    }
    if (source.rejected !== undefined) {
      this.rejected = new PolygonStyle(source.rejected);
    }
    if (source.completed !== undefined) {
      this.completed = new PolygonStyle(source.completed);
    }
  }
}

/**
Configuration of the round badge on find and pick ar layer.
*/
export class FindAndPickBadgeConfiguration extends PartiallyConstructible {
  /**
    Appearance of the badge when a barcode is partially scanned.
    */
  public partiallyScanned: BadgeStyle = new BadgeStyle({
    visible: true,
    background: new BackgroundStyle({
      strokeColor: '#FFFFFF30',
      fillColor: '?sbColorWarning',
      strokeWidth: 0.0,
    }),
    foregroundColor: '?sbColorOnSurface',
  });
  /**
    Appearance of the badge when a barcode is rejected.
    */
  public rejected: BadgeStyle = new BadgeStyle({
    visible: true,
    background: new BackgroundStyle({
      strokeColor: '#FFFFFF30',
      fillColor: '?sbColorNegative',
      strokeWidth: 0.0,
    }),
    foregroundColor: '?sbColorOnSurface',
  });
  /**
    Appearance of the badge when a barcode is completed.
    */
  public completed: BadgeStyle = new BadgeStyle({
    visible: true,
    background: new BackgroundStyle({
      strokeColor: '#FFFFFF30',
      fillColor: '?sbColorPositive',
      strokeWidth: 0.0,
    }),
    foregroundColor: '?sbColorOnSurface',
  });

  /** @param source {@displayType `DeepPartial<FindAndPickBadgeConfiguration>`} */
  public constructor(source: DeepPartial<FindAndPickBadgeConfiguration> = {}) {
    super();
    if (source.partiallyScanned !== undefined) {
      this.partiallyScanned = new BadgeStyle(source.partiallyScanned);
    }
    if (source.rejected !== undefined) {
      this.rejected = new BadgeStyle(source.rejected);
    }
    if (source.completed !== undefined) {
      this.completed = new BadgeStyle(source.completed);
    }
  }
}

/**
Configuration of the AR overlay.
*/
export class ArOverlayFindAndPickConfiguration extends PartiallyConstructible {
  /**
    Control the visibility of the user guidance.
    Default is false
    */
  public visible: boolean = false;
  /**
    If enabled, the scanner will always immediately scan a barcode in the viewfinder or the camera view. The overlay will mark the scanned barcodes and stays above them.
    Default is true
    */
  public automaticSelectionEnabled: boolean = true;
  /**
    Configuration of the overlay polygon displayed on top of a barcode in the camera preview.
    */
  public polygon: FindAndPickArOverlayPolygonConfiguration =
    new FindAndPickArOverlayPolygonConfiguration({});
  /**
    Configuration of the round badge on find and pick ar layer.
    */
  public badge: FindAndPickBadgeConfiguration = new FindAndPickBadgeConfiguration({});

  /** @param source {@displayType `DeepPartial<ArOverlayFindAndPickConfiguration>`} */
  public constructor(source: DeepPartial<ArOverlayFindAndPickConfiguration> = {}) {
    super();
    if (source.visible !== undefined) {
      this.visible = source.visible;
    }
    if (source.automaticSelectionEnabled !== undefined) {
      this.automaticSelectionEnabled = source.automaticSelectionEnabled;
    }
    if (source.polygon !== undefined) {
      this.polygon = new FindAndPickArOverlayPolygonConfiguration(source.polygon);
    }
    if (source.badge !== undefined) {
      this.badge = new FindAndPickBadgeConfiguration(source.badge);
    }
  }
}
