import 'package:json_annotation/json_annotation.dart';
import 'package:nextcloud/nextcloud.dart';

part 'cacheableFile.g.dart';

@JsonSerializable(explicitToJson: true)
class CacheableFile {
  late String path;
  late bool isDirectory;
  late String name;
  String? mimeType;
  int? size;
  String? eTag;
  DateTime? createdAt;
  DateTime? modifiedAt;
  String? sort;

  @JsonKey(includeFromJson: false, includeToJson: false)
  bool currentlyDownloading = false;


  CacheableFile({required this.path, required this.isDirectory, required this.name, this.mimeType, this.size, this.eTag, this.createdAt, this.modifiedAt});

  CacheableFile.fromDavFile(WebDavFile file) {
    path = file.path;
    isDirectory = file.isDirectory;
    name = file.name;
    mimeType = file.mimeType;
    size = file.size;
    eTag = file.etag;
    createdAt = file.createdDate;
    modifiedAt = file.lastModified;
  }

  factory CacheableFile.fromJson(Map<String, dynamic> json) => _$CacheableFileFromJson(json);
  Map<String, dynamic> toJson() => _$CacheableFileToJson(this);
}