ente/lib/models/billing_plan.dart

228 lines
4.8 KiB
Dart
Raw Normal View History

// @dart=2.9
2021-01-05 09:41:32 +00:00
import 'dart:convert';
2021-03-02 06:35:10 +00:00
import 'package:flutter/foundation.dart';
class BillingPlans {
final List<BillingPlan> plans;
final FreePlan freePlan;
BillingPlans({
this.plans,
this.freePlan,
});
BillingPlans copyWith({
List<BillingPlan> plans,
FreePlan freePlan,
}) {
return BillingPlans(
plans: plans ?? this.plans,
freePlan: freePlan ?? this.freePlan,
);
}
Map<String, dynamic> toMap() {
return {
'plans': plans?.map((x) => x?.toMap())?.toList(),
'freePlan': freePlan?.toMap(),
};
}
factory BillingPlans.fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return BillingPlans(
plans: List<BillingPlan>.from(
2022-06-11 08:23:52 +00:00
map['plans']?.map((x) => BillingPlan.fromMap(x)),
),
2021-03-02 06:35:10 +00:00
freePlan: FreePlan.fromMap(map['freePlan']),
);
}
String toJson() => json.encode(toMap());
factory BillingPlans.fromJson(String source) =>
BillingPlans.fromMap(json.decode(source));
@override
String toString() => 'BillingPlans(plans: $plans, freePlan: $freePlan)';
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is BillingPlans &&
listEquals(o.plans, plans) &&
o.freePlan == freePlan;
}
@override
int get hashCode => plans.hashCode ^ freePlan.hashCode;
}
class FreePlan {
final int storage;
final int duration;
final String period;
FreePlan({
this.storage,
this.duration,
this.period,
});
FreePlan copyWith({
int storage,
int duration,
String period,
}) {
return FreePlan(
storage: storage ?? this.storage,
duration: duration ?? this.duration,
period: period ?? this.period,
);
}
Map<String, dynamic> toMap() {
return {
'storage': storage,
'duration': duration,
'period': period,
};
}
factory FreePlan.fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return FreePlan(
storage: map['storage'],
duration: map['duration'],
period: map['period'],
);
}
String toJson() => json.encode(toMap());
factory FreePlan.fromJson(String source) =>
FreePlan.fromMap(json.decode(source));
@override
String toString() =>
'FreePlan(storage: $storage, duration: $duration, period: $period)';
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is FreePlan &&
o.storage == storage &&
o.duration == duration &&
o.period == period;
}
@override
int get hashCode => storage.hashCode ^ duration.hashCode ^ period.hashCode;
}
2021-01-05 09:41:32 +00:00
class BillingPlan {
final String id;
2021-01-06 08:47:18 +00:00
final String androidID;
final String iosID;
2021-05-19 15:47:16 +00:00
final String stripeID;
2021-02-01 10:20:39 +00:00
final int storage;
2021-01-05 09:41:32 +00:00
final String price;
2021-01-06 08:47:18 +00:00
final String period;
2021-01-05 09:41:32 +00:00
BillingPlan({
this.id,
2021-01-06 08:47:18 +00:00
this.androidID,
this.iosID,
2021-05-19 15:47:16 +00:00
this.stripeID,
2021-02-01 10:20:39 +00:00
this.storage,
2021-01-05 09:41:32 +00:00
this.price,
2021-01-06 08:47:18 +00:00
this.period,
2021-01-05 09:41:32 +00:00
});
BillingPlan copyWith({
String id,
2021-01-06 08:47:18 +00:00
String androidID,
String iosID,
2021-05-19 15:47:16 +00:00
String stripeID,
2021-02-01 10:21:25 +00:00
int storage,
2021-01-05 09:41:32 +00:00
String price,
2021-01-06 08:47:18 +00:00
String period,
2021-01-05 09:41:32 +00:00
}) {
return BillingPlan(
id: id ?? this.id,
2021-01-06 08:47:18 +00:00
androidID: androidID ?? this.androidID,
iosID: iosID ?? this.iosID,
2021-05-19 15:47:16 +00:00
stripeID: stripeID ?? this.stripeID,
2021-02-01 10:21:25 +00:00
storage: storage ?? this.storage,
2021-01-05 09:41:32 +00:00
price: price ?? this.price,
2021-01-06 08:47:18 +00:00
period: period ?? this.period,
2021-01-05 09:41:32 +00:00
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
2021-01-06 08:47:18 +00:00
'androidID': androidID,
'iosID': iosID,
2021-05-19 15:47:16 +00:00
'stripeID': stripeID,
2021-02-01 10:20:39 +00:00
'storage': storage,
2021-01-05 09:41:32 +00:00
'price': price,
2021-01-06 08:47:18 +00:00
'period': period,
2021-01-05 09:41:32 +00:00
};
}
factory BillingPlan.fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return BillingPlan(
id: map['id'],
2021-01-06 08:47:18 +00:00
androidID: map['androidID'],
iosID: map['iosID'],
2021-05-19 15:47:16 +00:00
stripeID: map['stripeID'],
2021-02-01 10:20:39 +00:00
storage: map['storage'],
2021-01-05 09:41:32 +00:00
price: map['price'],
2021-01-06 08:47:18 +00:00
period: map['period'],
2021-01-05 09:41:32 +00:00
);
}
String toJson() => json.encode(toMap());
factory BillingPlan.fromJson(String source) =>
BillingPlan.fromMap(json.decode(source));
@override
String toString() {
2021-05-19 15:47:16 +00:00
return 'BillingPlan(id: $id, androidID: $androidID, iosID: $iosID, stripeID: $stripeID, storage: $storage, price: $price, period: $period)';
2021-01-05 09:41:32 +00:00
}
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is BillingPlan &&
o.id == id &&
2021-01-06 08:47:18 +00:00
o.androidID == androidID &&
o.iosID == iosID &&
2021-05-19 15:47:16 +00:00
o.stripeID == stripeID &&
2021-02-01 10:20:39 +00:00
o.storage == storage &&
2021-01-05 09:41:32 +00:00
o.price == price &&
2021-01-06 08:47:18 +00:00
o.period == period;
2021-01-05 09:41:32 +00:00
}
@override
int get hashCode {
2021-01-06 08:47:18 +00:00
return id.hashCode ^
androidID.hashCode ^
iosID.hashCode ^
2021-05-19 15:47:16 +00:00
stripeID.hashCode ^
2021-02-01 10:20:39 +00:00
storage.hashCode ^
2021-01-06 08:47:18 +00:00
price.hashCode ^
period.hashCode;
2021-01-05 09:41:32 +00:00
}
}