ente/lib/models/subscription.dart

66 lines
1.4 KiB
Dart
Raw Normal View History

import 'dart:convert';
class Subscription {
2021-01-18 17:02:44 +00:00
final int id;
2021-01-18 16:20:35 +00:00
final int storageInMBs;
2021-01-18 17:02:44 +00:00
final int expiryTime;
Subscription({
this.id,
2021-01-18 16:20:35 +00:00
this.storageInMBs,
2021-01-18 17:02:44 +00:00
this.expiryTime,
});
Subscription copyWith({
2021-01-18 17:02:44 +00:00
int id,
int storageInMBs,
int expiryTime,
}) {
return Subscription(
id: id ?? this.id,
2021-01-18 16:20:35 +00:00
storageInMBs: storageInMBs ?? this.storageInMBs,
2021-01-18 17:02:44 +00:00
expiryTime: expiryTime ?? this.expiryTime,
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
2021-01-18 16:20:35 +00:00
'storageInMBs': storageInMBs,
2021-01-18 17:02:44 +00:00
'expiryTime': expiryTime,
};
}
factory Subscription.fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return Subscription(
id: map['id'],
2021-01-18 16:20:35 +00:00
storageInMBs: map['storageInMBs'],
2021-01-18 17:02:44 +00:00
expiryTime: map['expiryTime'],
);
}
String toJson() => json.encode(toMap());
factory Subscription.fromJson(String source) =>
Subscription.fromMap(json.decode(source));
@override
String toString() =>
2021-01-18 17:02:44 +00:00
'Subscription(id: $id, storageInMBs: $storageInMBs, expiryTime: $expiryTime)';
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is Subscription &&
o.id == id &&
2021-01-18 16:20:35 +00:00
o.storageInMBs == storageInMBs &&
2021-01-18 17:02:44 +00:00
o.expiryTime == expiryTime;
}
@override
2021-01-18 17:02:44 +00:00
int get hashCode => id.hashCode ^ storageInMBs.hashCode ^ expiryTime.hashCode;
}