// device.dart — 已登录设备(GET /v1/me/devices)。
class Device {
  const Device({
    required this.uuid,
    required this.name,
    required this.platform,
    this.lastSeen,
  });

  final String uuid;
  final String name;

  /// 'ios' | 'android' | 'windows' | 'macos'。
  final String platform;

  /// 最近活跃(UTC);从未上线为 null。
  final DateTime? lastSeen;

  factory Device.fromJson(Map<String, dynamic> m) {
    final ls = m['last_seen'] as String?;
    return Device(
      uuid: m['uuid'] as String? ?? '',
      name: m['name'] as String? ?? '',
      platform: m['platform'] as String? ?? '',
      lastSeen: (ls != null && ls.isNotEmpty) ? DateTime.tryParse(ls) : null,
    );
  }
}
