//
//  CameraFactory.swift
//  otg_swift
//
//  Created by hanqiu on 2026/7/2.
//

import Foundation
@preconcurrency import ImageCaptureCore

/// 根据 PlatformDetector 结果创建对应品牌的 CameraDriver 实例。
enum CameraFactory {
    /// 创建品牌 Driver；`unknown` 平台返回 nil。
    static func makeDriver(
        platform: CameraPlatform,
        device: ICCameraDevice,
        deviceInfo: CameraDeviceInfo
    ) -> CameraDriver? {
        OTGLog.info(.factory, "creating driver for platform=\(platform.rawValue), device=\(deviceInfo.name)")

        switch platform {
        case .nikon:
            let driver = NikonCameraDriver(device: device, deviceInfo: deviceInfo)
            OTGLog.info(.factory, "created NikonCameraDriver")
            return driver
        case .canon:
            let driver = CanonCameraDriver(device: device, deviceInfo: deviceInfo)
            OTGLog.info(.factory, "created CanonCameraDriver")
            return driver
        case .sony:
            let driver = SonyCameraDriver(device: device, deviceInfo: deviceInfo)
            OTGLog.info(.factory, "created SonyCameraDriver")
            return driver
        case .unknown:
            OTGLog.error(.factory, "refused to create driver for unknown platform")
            return nil
        }
    }
}
