import ContentsquareSDK
import HeapSwiftCore

public protocol _CSQ {
    static func start()
    static func handle(url: URL)
    static func optIn()
    static func optOut()
    static func addDynamicVar(_ dVar: ContentsquareSDK.DynamicVar)
    static func stop()
    static func pauseTracking()
    static func resumeTracking()
    static func identify(_ identity: String)
    static func trackScreenview(_ name: String, cvars: [ContentsquareSDK.CustomVar])
    static func resetIdentity()
    static func configureProductAnalytics(environmentID: String, additionalOptions: [ContentsquareSDK.ProductAnalyticsOption: Any])
    static func trackTransaction(_ transaction: ContentsquareSDK.Transaction)
    static func sendUserIdentifier(_ userIdentifier: String)
    static func setDefaultMasking(_ masked: Bool)
    static func trackEvent(_ name: String, properties: [String: PropertyValue])
    static func mask(viewsOfType: UIView.Type)
    static func unmask(viewsOfType: UIView.Type)
    static func setURLMaskingPatterns(_ patterns: [String])
    static func addEventProperties(_ properties: [String: PropertyValue])
    static func removeEventProperty(_ key: String)
    static func clearEventProperties()
    static func addUserProperties(_ properties: [String: PropertyValue])
    static var metadata: ContentsquareSDK.CSQ.Metadata { get }
}

public protocol _Heap {
    func __track(_ event: String, properties: [String: any HeapSwiftCore.HeapObjcPropertyValue], sourceInfo: HeapSwiftCore.SourceInfo?)
}

extension Heap: _Heap {
}

@objc
protocol _WebViewHandler {

    func registerWebview(withTag webViewTag:NSNumber,
                         in uiManager:_RCTUIManager)
    func unregisterWebview(withTag webViewTag:NSNumber,
                           from uiManager:_RCTUIManager)
}

public protocol _HeapBridgeSupport {
    var delegate: (any HeapSwiftCore.HeapBridgeSupportDelegate)? { get set }
    func handleInvocation(method: String, arguments: [String : Any]) throws -> (any HeapSwiftCore.JSONEncodable)?
    func handleResult(callbackId: String, data: Any?, error: String?)
}

extension HeapBridgeSupport: _HeapBridgeSupport {}

extension CSQ: _CSQ {}

import ContentsquareModule
import WebKit

@objc
public protocol _RCTUIManager {
    // NOTE: warning for different parameters optionality in objC is incorrect
    func view(forReactTag reactTag: NSNumber) -> UIView?
}
extension RCTUIManager: _RCTUIManager {}

@objc
public protocol _Contentsquare {
    static func start()
    static func stopTracking()
    static func resumeTracking()
    static func optIn()
    static func optOut()
    static func handle(url: URL)
    static var userID: String? { get }
    static var currentSessionReplayLink: URL? { get }
    static func send(transaction: ContentsquareModule.CustomerTransaction)
    static func send(screenViewWithName name: String, cvars: [ContentsquareModule.CustomVar])
    static func send(dynamicVar: ContentsquareModule.DynamicVar)
    static func register(webView: WKWebView)
    static func unregister(webView: WKWebView)
    static func mask(view: UIView)
    static func unmask(view: UIView)
    static func mask(viewsOfType: UIView.Type)
    static func unmask(viewsOfType: UIView.Type)
    static func setDefaultMasking(_ isMasking: Bool)
    static func sendUserIdentifier(_ userIdentifier: String)
    static func onSessionReplayLinkChange(_ action: ((URL) -> Void)?)
}


extension Contentsquare: _Contentsquare {}


@objc
protocol _ErrorAnalysis {
    static func setURLMaskingPatterns(_ patterns: [String])
}

extension ErrorAnalysis: _ErrorAnalysis {}
