import Foundation
import os.log

/**
 * Internal logger for BigCrunch Ads SDK
 *
 * Uses os_log for unified logging, visible in Console.app and terminal
 * without requiring the Xcode debugger to be attached.
 * All logs use the "BCrunch" subsystem for easy filtering.
 * Logging can be disabled in production by setting isEnabled = false.
 * Error logs are always shown regardless of isEnabled flag.
 */
internal class BCLogger {

    private static let log = OSLog(subsystem: "com.bigcrunch.ads", category: "BCrunch")

    /**
     * Enable/disable debug logging
     * Defaults to false for production builds
     */
    static var isEnabled = false

    /**
     * Verbose log - detailed debugging information
     */
    static func verbose(_ message: String) {
        if isEnabled {
            os_log("[BCrunch:VERBOSE] %{public}@", log: log, type: .debug, message)
        }
    }

    /**
     * Debug log - general debugging information
     */
    static func debug(_ message: String) {
        if isEnabled {
            os_log("[BCrunch:DEBUG] %{public}@", log: log, type: .debug, message)
        }
    }

    /**
     * Info log - informational messages
     */
    static func info(_ message: String) {
        if isEnabled {
            os_log("[BCrunch:INFO] %{public}@", log: log, type: .info, message)
        }
    }

    /**
     * Warning log - potential issues
     */
    static func warning(_ message: String) {
        if isEnabled {
            os_log("[BCrunch:WARNING] %{public}@", log: log, type: .default, message)
        }
    }

    /**
     * Error log - critical errors
     * Always logs regardless of isEnabled flag
     */
    static func error(_ message: String) {
        // Always log errors
        os_log("[BCrunch:ERROR] %{public}@", log: log, type: .error, message)
    }
}
