import 'package:equatable/equatable.dart';
import 'document_capabilities.dart';

class ViewerSession extends Equatable {
  final Uri viewUrl;
  final DocumentCapabilities capabilities;
  final String token;
  final DateTime expiresAt;
  final FileInfo? fileInfo;

  const ViewerSession({
    required this.viewUrl,
    required this.capabilities,
    required this.token,
    required this.expiresAt,
    this.fileInfo,
  });

  @override
  List<Object?> get props => [
    viewUrl,
    capabilities,
    token,
    expiresAt,
    fileInfo,
  ];

  factory ViewerSession.fromJson(Map<String, dynamic> json) {
    return ViewerSession(
      viewUrl: Uri.parse(json['viewUrl']),
      capabilities: DocumentCapabilities.fromJson(json['capabilities']),
      token: json['token'],
      expiresAt: DateTime.parse(json['expiresAt']),
      fileInfo: json['fileInfo'] != null
          ? FileInfo.fromJson(json['fileInfo'])
          : null,
    );
  }
}
