//
//  CameraTetheringLogger.swift
//  suixinkan
//
//  Created by Codex on 2026/6/29.
//

import Foundation
import os

/// 相机有线传输模块日志工具，按 Camera / Transfer / PTP 分类输出。
enum CameraTetheringLogger {
    /// 控制台统一前缀，便于 Xcode / Console.app 过滤：`[OTG]`
    static let logPrefix = "[OTG]"

    private static let subsystem = Bundle.main.bundleIdentifier ?? "com.suixinkan"

    static let camera = Logger(subsystem: subsystem, category: "Camera")
    static let transfer = Logger(subsystem: subsystem, category: "Transfer")
    static let ptp = Logger(subsystem: subsystem, category: "PTP")

    /// 写入指定分类的 info 日志，消息前自动附加 `[OTG]` 前缀。
    static func log(_ message: String, logger: Logger = camera) {
        let formatted = prefixed(message)
        logger.info("\(formatted, privacy: .public)")
    }

    /// 为消息附加 OTG 统一前缀；若已含前缀则不再重复添加。
    static func prefixed(_ message: String) -> String {
        if message.hasPrefix(logPrefix) {
            return message
        }
        return "\(logPrefix) \(message)"
    }
}
