//
//  JedAIReactNativeSDK.swift
//  JedAIReactNative
//
//  Created by Alexey Siginur on 10/06/2025.
//

import Foundation
import JedAIAppKit

// MARK: - Typealias for ReactNative platform

// `AnagogSDKWrapper` is a public class across all multi-platform packages
// Each platform(React-Native, Flutter, Cordova, etc) must implement it's own wrapper
//
// Since the `@obj` attribute can't be used with a `typealias` declaration,
// we define the class directly as a workaround.
@objc public class AnagogSDKWrapper: NSObject {
    @objc public static let shared = JedAIReactNativeSDK()
    
    private override init() {
        // Should not be called directly, use `shared` instead
    }
}


// MARK: - Custom React Native SDK

@objc public class JedAIReactNativeSDK: AnagogSDK {
    init() {
        let configurator = JedAIReactNativeStartupConfigurator()
        let storage = PersistentStorage(userDefaults: .standard)
        super.init(configurator: configurator, storage: storage)
        configurator.sdkWrapper = self
    }
    
    // MARK: - React Native related code
    // Add any additional properties and logics related to React Native platform
    
    public override func startup(withOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) {
        super.startup(withOptions: launchOptions)
    }
}


// MARK: - Custom startup configurator for React Native platform

class JedAIReactNativeStartupConfigurator: AnagogStartupConfigurator {
    
    override func configureFromJSON(_ configs: [String : Any]) {
        super.configureFromJSON(configs)

        // Validate initialization
        if self.sdkWrapper == nil {
            assertionFailure("Wrong AnagogSDK integration: `sdkWrapper` is not set. Please contact support.")
        }
        
        if let _ = self.sdkWrapper as? JedAIReactNativeSDK {
            // Add any additional configurations related to React Native platform
        }
        
        // Add any additional configurations related to React Native platform
    }
    
}


// MARK: - Custom API bridge implementations

extension AnagogBridgeAPI {
    
    // Add any additional API methods related to React Native platform
    
}
