import Foundation
import OSLog

public struct SaplingLogger: Sendable {
    public enum Category: String, Sendable {
        case app
        case workspace
        case git
        case editor
        case storage
        case rendering
    }

    private let subsystem: String

    public init(subsystem: String = "app.sapling.Sapling") {
        self.subsystem = subsystem
    }

    public func debug(_ message: String, category: Category) {
        logger(for: category).debug("\(message, privacy: .public)")
    }

    public func info(_ message: String, category: Category) {
        logger(for: category).info("\(message, privacy: .public)")
    }

    public func warning(_ message: String, category: Category) {
        logger(for: category).warning("\(message, privacy: .public)")
    }

    public func error(_ message: String, category: Category) {
        logger(for: category).error("\(message, privacy: .public)")
    }

    private func logger(for category: Category) -> Logger {
        Logger(subsystem: subsystem, category: category.rawValue)
    }
}
