//
//  FirebaseTracking.swift
//  SodaLive
//
//  Created by klaus on 3/10/25.
//

import Firebase

class FirebaseTracking {
    static let shared = FirebaseTracking()
    
    func signUp(method: String) {
        Analytics.logEvent(
            AnalyticsEventSignUp,
            parameters: [
                AnalyticsParameterMethod: method,
                "marketing_pid": UserDefaults.string(forKey: .marketingPid)
            ]
        )
    }
    
    func login(method: String) {
        Analytics.logEvent(
            AnalyticsEventLogin,
            parameters: [
                AnalyticsParameterMethod: method,
                "marketing_pid": UserDefaults.string(forKey: .marketingPid)
            ]
        )
    }
    
    func logUtm() {
        let utmSource = AppState.shared.marketingUtmSource.trimmingCharacters(in: .whitespacesAndNewlines)
        let utmMedium = AppState.shared.marketingUtmMedium.trimmingCharacters(in: .whitespacesAndNewlines)
        let utmCampaign = AppState.shared.marketingUtmCampaign.trimmingCharacters(in: .whitespacesAndNewlines)
        
        if !utmSource.isEmpty && !utmMedium.isEmpty && !utmCampaign.isEmpty {
            Analytics.logEvent("ad_partner_campaign_details", parameters: [
                AnalyticsParameterSource: utmSource,
                AnalyticsParameterMedium: utmMedium,
                AnalyticsParameterCampaign: utmCampaign
            ])
        }
    }
}
