import Foundation
import FacebookCore

// MARK: - Facebook事件管理器
class FacebookEventManager {
    
    static let shared = FacebookEventManager()
    
    private init() {}
    
    // MARK: - 初始化Facebook SDK
    func configure() {
        // 配置Facebook SDK
        FacebookCore.ApplicationDelegate.shared.application(
            UIApplication.shared,
            didFinishLaunchingWithOptions: nil
        )

    }
    
    // MARK: - 记录应用启动事件
    func logAppLaunch() {
        FacebookCore.AppEvents.shared.logEvent(.completedRegistration)
    }
    
    // MARK: - 记录二维码扫描事件
    func logQRCodeScan(type: String) {
        let parameters = [
            FacebookCore.AppEvents.ParameterName.contentType: "qr_code",
            FacebookCore.AppEvents.ParameterName.content: type
        ]
        FacebookCore.AppEvents.shared.logEvent(.viewedContent, parameters: parameters)
    }
    
    // MARK: - 记录二维码生成事件
    func logQRCodeGeneration(type: String) {
        let parameters = [
            FacebookCore.AppEvents.ParameterName.contentType: "qr_code_generation",
            FacebookCore.AppEvents.ParameterName.content: type
        ]
        FacebookCore.AppEvents.shared.logEvent(.completedTutorial, parameters: parameters)
    }
    
    // MARK: - 记录功能使用事件
    func logFeatureUsage(feature: String) {
        let parameters = [
            FacebookCore.AppEvents.ParameterName.contentType: "feature_usage",
            FacebookCore.AppEvents.ParameterName.content: feature
        ]
        FacebookCore.AppEvents.shared.logEvent(.searched, parameters: parameters)
    }
    
    // MARK: - 记录分享事件
    func logShare(contentType: String) {
        let parameters = [
            FacebookCore.AppEvents.ParameterName.contentType: contentType
        ]
        FacebookCore.AppEvents.shared.logEvent(.completedTutorial, parameters: parameters)
    }
    
    // MARK: - 记录应用内购买事件（如果有的话）
    func logPurchase(amount: Double, currency: String = "USD") {
        FacebookCore.AppEvents.shared.logPurchase(amount: amount, currency: currency)
    }
}
