import Foundation
import ScanbotSDK
import ScanbotSDKNativeWrapper

@objc public protocol RNScanbotDocumentScannerEventDelegate {
    
    @objc func onScannedDocument(_ originalImageRef: SBSDKImageRef, _ croppedImageRef: SBSDKImageRef?, _ detectionResult: String?)
    
    @objc func onDocumentDetectionStatus(_ status: String)
    
    @objc func onError(_ errorMessage: String, errorCode: Int)
    
}

extension RNScanbotDocumentScannerEventDelegate {
    
    func onError(_ error: SBError){
        onError(error.localizedDescription, errorCode: error.errorCode)
    }
}

extension SBSDKDocumentScannerViewController {
    
  func withAutoSnapConfigCopy() {
      let config = SBSDKDocumentScannerPolygonConfiguration()
      config.enabled = autoSnapProgressPolygonConfiguration.enabled
      config.strokeWidth = autoSnapProgressPolygonConfiguration.strokeWidth
      config.strokeColor = autoSnapProgressPolygonConfiguration.strokeColor
      autoSnapProgressPolygonConfiguration = config
    }
}

extension UIColor {
    var transparentAlpha: UIColor {
        var alpha: CGFloat = 0
        getRed(nil, green: nil, blue: nil, alpha: &alpha)
        return withAlphaComponent(alpha * 0.2)
    }
}

struct DocumentScannerDefaultValues {
  let acceptedAngleScore = 75
  let acceptedBrightnessThreshold = 0
  let acceptedSizeScore = 80
  let autoSnappingEnabled = SBSDKAutoSnappingMode.enabled
  let autoSnappingSensitivity: Float = 0.66
  let autoSnappingDelay = 1.0
  let ignoreOrientationMismatch = false
  let acceptedAspectRatioScore = 85
  let cameraModule = SBSDKCameraDevice.defaultBackFacingCamera
  let cameraPreviewMode = SBSDKVideoContentMode.fillIn
  let photoQualityPrioritization = SBSDKCapturePhotoQualityPrioritization.balanced
  let finderEnabled = false
  let finderLineColor = SBComponentUtils.fromRgbAHex("#FFFFFF")
  let finderOverlayColor = SBComponentUtils.fromRgbAHex("#000000CC")
  let finderLineWidth: Float = 2.0
  let finderCornerRadius = 10.0
  let finderMinimumPadding = UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0)
  let finderAspectRatio = SBSDKAspectRatio(width: 1.0, height: 1.4142)
  let polygonEnabled = true
  let polygonBackgroundColor = SBComponentUtils.fromRgbAHex("#FFFFFF").transparentAlpha
  let polygonBackgroundColorOK = SBComponentUtils.fromRgbAHex("#FFFFFF").transparentAlpha
  let polygonColor = SBComponentUtils.fromRgbAHex("#FF00004D")
  let polygonColorOK = SBComponentUtils.fromRgbAHex("#00CEA6FF")
  let polygonLineWidth = 3.0
  let polygonCornerRadius = 8.0
  let polygonAutoSnapProgressEnabled = true
  let polygonAutoSnapProgressColor = SBComponentUtils.fromRgbAHex("#87F2DEFF")
  let polygonAutoSnapProgressLineWidth = 5.0
}
