import 'package:equatable/equatable.dart';

class FileInfo extends Equatable {
  final String name;
  final int size;
  final DateTime? lastModified;
  final String? modifiedByName;

  const FileInfo({
    required this.name,
    required this.size,
    this.lastModified,
    this.modifiedByName,
  });

  @override
  List<Object?> get props => [name, size, lastModified, modifiedByName];

  factory FileInfo.fromJson(Map<String, dynamic> json) {
    return FileInfo(
      name: json['name'] ?? '',
      size: json['size'] ?? 0,
      lastModified: json['lastModified'] != null
          ? DateTime.tryParse(json['lastModified'])
          : null,
      modifiedByName: json['modifiedByName'],
    );
  }
}

class DocumentCapabilities extends Equatable {
  final bool canEdit;
  final bool canAnnotate;
  final bool isPdf;
  final String mimeType;

  const DocumentCapabilities({
    required this.canEdit,
    required this.canAnnotate,
    required this.isPdf,
    required this.mimeType,
  });

  @override
  List<Object?> get props => [canEdit, canAnnotate, isPdf, mimeType];

  factory DocumentCapabilities.fromJson(Map<String, dynamic> json) {
    return DocumentCapabilities(
      canEdit: json['canEdit'],
      canAnnotate: json['canAnnotate'],
      isPdf: json['isPdf'],
      mimeType: json['mimeType'] ?? 'application/octet-stream',
    );
  }

  bool get isImage => mimeType.startsWith('image/');
  bool get isText => mimeType.startsWith('text/');
  bool get isOffice =>
      mimeType.contains('word') ||
      mimeType.contains('spreadsheet') ||
      mimeType.contains('presentation');
}
