/// 获取 TOKEN 响应模型
class GetTokenResModel {
  GetTokenResModel({required this.deviceAccessToken});

  final String deviceAccessToken;

  factory GetTokenResModel.fromJson(Map<String, dynamic> json) {
    return GetTokenResModel(
      deviceAccessToken: (json['deviceAccessToken'] ?? '').toString(),
    );
  }

  Map<String, dynamic> toJson() {
    return {'deviceAccessToken': deviceAccessToken};
  }
}

/// 查看录像响应模型
class GetRecordListResModel {
  String? path;
  List<RecordListItem>? items;

  GetRecordListResModel({this.path, this.items});

  factory GetRecordListResModel.fromJson(Map<String, dynamic> json) {
    final rawItems = json['items'];
    return GetRecordListResModel(
      path: json['path']?.toString(),
      items: rawItems is! List
          ? []
          : rawItems
                .whereType<Map>()
                .map(
                  (x) => RecordListItem.fromJson(Map<String, dynamic>.from(x)),
                )
                .toList(),
    );
  }

  Map<String, dynamic> toJson() => {
    'path': path,
    'items': items == null
        ? []
        : List<dynamic>.from(items!.map((x) => x.toJson())),
  };
}

enum RecordItemType {
  file('file'),
  directory('dir');

  final String value;
  const RecordItemType(this.value);
}

class RecordListItem {
  String? name;
  String? path;
  String? type;
  int? size;
  DateTime? modTime;
  String? url;
  String? extension;

  RecordListItem({
    this.name,
    this.path,
    this.type,
    this.size,
    this.modTime,
    this.url,
    this.extension,
  });

  factory RecordListItem.fromJson(Map<String, dynamic> json) => RecordListItem(
    name: json['name'] ?? '',
    path: json['path'] ?? '',
    type: json['type'] ?? '',
    size: json['size'] ?? 0,
    modTime: json['modTime'] == null ? null : DateTime.parse(json['modTime']),
    url: json['url'] ?? '',
    extension: json['extension'] ?? '',
  );

  Map<String, dynamic> toJson() => {
    'name': name,
    'path': path,
    'type': type,
    'size': size,
    'modTime': modTime?.toIso8601String(),
    'url': url,
    'extension': extension,
  };
}
