export const PROTOCOL_VERSION = '1.0.0'

export const BLE_UUIDS = {
  SERVICE: '000002c4-0000-1000-8000-00805f9b34fb',
  BROADCAST_CHARACTERISTIC: '000002c1-0000-1000-8000-00805f9b34fb',
  WRITE_CHARACTERISTIC: '000002c5-0000-1000-8000-00805f9b34fb',
  READ_CHARACTERISTIC: '000002c6-0000-1000-8000-00805f9b34fb',
  REQUEST_MTU: 512,
  SCREEN_SIZE: 360,
} as const

export const FRAME_CONSTANTS = {
  HEAD_DEVICE_TO_APP: 0xb0,
  HEAD_APP_TO_DEVICE: 0xc7,
  // HEAD_APP_TO_DEVICE: 0xb1,

  MAX_DATA_SIZE: 496,
  HEADER_SIZE: 8,
  FOOTER_SIZE: 1,
  FRAME_INTERVAL: 35, // package transfer idle interval in ms, set 35 ms for ble device have enough time to process data
} as const

export type FRAME_HEAD = typeof FRAME_CONSTANTS.HEAD_DEVICE_TO_APP | typeof FRAME_CONSTANTS.HEAD_APP_TO_DEVICE

export const COMMAND_TYPES = {
  OTA_PACKAGE: 0x02,
  TRANSFER_BOOT_ANIMATION: 0x03,
  TRANSFER_ANI_VIDEO: 0x05,
  TRANSFER_JPEG_IMAGE: 0x06,
  GET_DEVICE_VERSION: 0x07,
  GET_DEVICE_INFO: 0x0d,
  BIND_DEVICE: 0x0f,
  UNBIND_DEVICE: 0x12,
  DELETE_FILE: 0x13,
  PREPARE_TRANSFER: 0x14,
} as const

export type APP_COMMAND_TYPES = (typeof COMMAND_TYPES)[keyof typeof COMMAND_TYPES] | number

export const EVENT_TYPES = {
  TRANSFER_OTA_PACKAGE: {
    name: 'onTransferOtaPackage',
    code: 0x02, // 2
  },
  TRANSFER_BOOT_ANIMATION: {
    name: 'onTransferBootAnimation',
    code: 0x03, // 3
  },
  TRANSFER_ANI_VIDEO: {
    name: 'onTransferAniVideo',
    code: 0x05, // 5
  },
  VERSION_INFO: {
    name: 'onVersionInfo',
    code: 0x07, // 7
  },
  DEVICE_INFO: {
    name: 'onDeviceInfo',
    code: 0x0d, // 13
  },
  BIND_DEVICE: {
    name: 'onBindDevice',
    code: 0x0f, // 15
  },
  UNBIND_DEVICE: {
    name: 'onUnbindDevice',
    code: 0x12, // 18
  },
  DELETE_FILE: {
    name: 'onDeleteFile',
    code: 0x13, // 19
  },
  PREPARE_TRANSFER: {
    name: 'onPrepareTransfer',
    code: 0x14, // 20
  },
}
