/// 版本信息模型
class VersionInfo {
  /// 版本号: "1.2.0"
  final String version;

  /// 版本代码: 120
  final int versionCode;

  /// APK 下载地址
  final String downloadUrl;

  /// 文件大小(字节)
  final int fileSize;

  /// 友好显示: "25.6 MB"
  final String fileSizeFriendly;

  /// SHA-256 校验
  final String sha256;

  /// 是否强制更新
  final bool forceUpdate;

  /// 更新日志
  final String? updateLog;

  /// 发布时间
  final DateTime releaseDate;

  const VersionInfo({
    required this.version,
    required this.versionCode,
    required this.downloadUrl,
    required this.fileSize,
    required this.fileSizeFriendly,
    required this.sha256,
    this.forceUpdate = false,
    this.updateLog,
    required this.releaseDate,
  });

  factory VersionInfo.fromJson(Map<String, dynamic> json) {
    return VersionInfo(
      version: json['version'] as String,
      versionCode: json['versionCode'] as int,
      downloadUrl: json['downloadUrl'] as String,
      fileSize: json['fileSize'] as int,
      fileSizeFriendly: json['fileSizeFriendly'] as String,
      sha256: json['sha256'] as String,
      forceUpdate: json['forceUpdate'] as bool? ?? false,
      updateLog: json['updateLog'] as String?,
      releaseDate: DateTime.parse(json['releaseDate'] as String),
    );
  }
}
