//
//  CanonPTPCommands.swift
//  otg_swift
//

import Foundation

/// 佳能 EOS 扩展 PTP 命令码与 GetEvent 传图事件码。
enum CanonPTPCommand {
    /// 标准 GetObjectInfo
    static let getObjectInfo: UInt16 = PTPStandardCommand.getObjectInfo
    /// 标准 GetObject
    static let getObject: UInt16 = PTPStandardCommand.getObject
    /// EOS GetObject (0x9104)
    static let eosGetObject: UInt16 = 0x9104
    /// EOS GetObjectInfoEx (0x9109)
    static let eosGetObjectInfoEx: UInt16 = 0x9109
    /// EOS SetRemoteMode (0x9114)
    static let setRemoteMode: UInt16 = 0x9114
    /// EOS SetEventMode (0x9115)
    static let setEventMode: UInt16 = 0x9115
    /// EOS GetEvent (0x9116)
    static let getEvent: UInt16 = 0x9116
    /// EOS TransferComplete (0x9117)
    static let transferComplete: UInt16 = 0x9117
    /// EOS PCHDDCapacity (0x911A)
    static let pchddCapacity: UInt16 = 0x911A
    /// EOS KeepDeviceOn (0x911D)
    static let keepDeviceOn: UInt16 = 0x911D
    /// 标准 ObjectAdded 事件
    static let objectAdded: UInt16 = PTPStandardCommand.objectAdded
    /// 标准 RequestObjectTransfer 事件
    static let requestObjectTransfer: UInt16 = PTPStandardCommand.requestObjectTransfer
    /// EOS ObjectAddedEx (0xC181)
    static let eosObjectAddedEx: UInt16 = 0xC181
    /// EOS ObjectInfoChangedEx (0xC187)
    static let eosObjectInfoChangedEx: UInt16 = 0xC187
    /// EOS ObjectContentChanged (0xC188)
    static let eosObjectContentChanged: UInt16 = 0xC188
    /// EOS RequestObjectTransfer (0xC186)
    static let eosRequestObjectTransfer: UInt16 = 0xC186
    /// EOS RequestObjectTransferDT (0xC190)
    static let eosRequestObjectTransferDT: UInt16 = 0xC190
    /// EOS RequestObjectTransferTS (0xC1A2)
    static let eosRequestObjectTransferTS: UInt16 = 0xC1A2
    /// EOS RequestObjectTransferEx (0xC1A7)，R8 等新机型快门后传图事件
    static let eosRequestObjectTransferEx: UInt16 = 0xC1A7
    /// EOS DevicePropChanged (0xC189)
    static let eosDevicePropChanged: UInt16 = 0xC189
    /// EOS PropValueDescChanged (0xC18A)
    static let eosPropValueDescChanged: UInt16 = 0xC18A
    /// SetRemoteMode 参数：启用
    static let remoteModeEnabled: UInt32 = 1
    /// SetEventMode 参数：启用
    static let eventModeEnabled: UInt32 = 1
}

/// libgphoto2 `ptp-pack.c` 中 Canon EOS 事件记录字段偏移（相对单条 record 起点）。
enum CanonEOSEventOffset {
    static let recordCode = 0x04
    static let objectHandle = 0x08
    static let transferObjectSize = 0x14
    static let transferFilename = 0x1C
    static let addedStorageID = 0x0C
    static let addedObjectSize = 0x1C
    static let addedFilename = 0x28
}

/// GetEvent 解析出的单条佳能 EOS 事件。
struct CanonEOSEvent {
    let code: UInt32
    let storageID: UInt32?
    let objectHandle: UInt32?
    let filename: String?
    let objectSize: UInt32?
}

/// Canon 远程会话初始化结果。
struct CanonRemoteSessionResult {
    let success: Bool
    let nextTransactionID: UInt32
}
