/opt/canhelp/apps/mobile/lib/models
Edit: /opt/canhelp/apps/mobile/lib/models/dashboard_data.dart (4016B)
class DashboardPlan {
final String id;
final String name;
final String role;
final String tier;
final String price;
const DashboardPlan({
required this.id,
required this.name,
required this.role,
required this.tier,
required this.price,
});
factory DashboardPlan.fromJson(Map
j) => DashboardPlan(
id: j['id'] as String,
name: j['name'] as String,
role: j['role'] as String,
tier: j['tier'] as String,
price: j['price']?.toString() ?? '0',
);
}
class DashboardExpiration {
final DateTime expiresAt;
final int daysLeft;
const DashboardExpiration({required this.expiresAt, required this.daysLeft});
factory DashboardExpiration.fromJson(Map j) =>
DashboardExpiration(
expiresAt: DateTime.parse(j['expiresAt'] as String),
daysLeft: j['daysLeft'] as int? ?? 0,
);
}
class DashboardUsage {
final int? messagesLeft;
final int? ordersLeft;
final int messagesSent;
final int ordersMade;
const DashboardUsage({
this.messagesLeft,
this.ordersLeft,
required this.messagesSent,
required this.ordersMade,
});
factory DashboardUsage.fromJson(Map j) => DashboardUsage(
messagesLeft: j['messagesLeft'] as int?,
ordersLeft: j['ordersLeft'] as int?,
messagesSent: j['messagesSent'] as int? ?? 0,
ordersMade: j['ordersMade'] as int? ?? 0,
);
}
class DashboardData {
final DashboardPlan? plan;
final DashboardExpiration? planExpiration;
final DashboardUsage usage;
final Map stats;
final Map? features;
final String? personalSiteSlug;
final bool showPricing;
const DashboardData({
this.plan,
this.planExpiration,
required this.usage,
required this.stats,
this.features,
this.personalSiteSlug,
this.showPricing = true,
});
String get tier => plan?.tier ?? 'free';
bool get isPro => tier == 'pro';
bool get isUltimate => tier == 'ultimate';
bool get isPaid => isPro || isUltimate;
bool feature(String key) {
final v = features?[key];
if (v == null) return false;
if (v is bool) return v;
return false;
}
factory DashboardData.fromJson(Map j) => DashboardData(
plan: j['plan'] != null
? DashboardPlan.fromJson(j['plan'] as Map)
: null,
planExpiration: j['planExpiration'] != null
? DashboardExpiration.fromJson(
j['planExpiration'] as Map,
)
: null,
usage: j['usage'] != null
? DashboardUsage.fromJson(j['usage'] as Map)
: DashboardUsage(messagesSent: 0, ordersMade: 0),
stats: j['stats'] as Map? ?? {},
features: j['features'] as Map?,
personalSiteSlug: j['personalSiteSlug'] as String?,
showPricing: j['showPricing'] as bool? ?? true,
);
}
class PlanItem {
final String id;
final String name;
final String role;
final String tier;
final double price;
final double? oldPrice;
final int? maxMessagesPerDay;
final int? maxOrdersPerDay;
final Map raw;
const PlanItem({
required this.id,
required this.name,
required this.role,
required this.tier,
required this.price,
this.oldPrice,
this.maxMessagesPerDay,
this.maxOrdersPerDay,
required this.raw,
});
factory PlanItem.fromJson(Map j) => PlanItem(
id: j['id'] as String,
name: j['name'] as String,
role: j['role'] as String,
tier: j['tier'] as String,
price:
double.tryParse(j['price']?.toString() ?? '') ??
(j['price'] as num?)?.toDouble() ??
0.0,
oldPrice: j['oldPrice'] != null
? (double.tryParse(j['oldPrice']!.toString()) ??
(j['oldPrice'] as num?)?.toDouble())
: null,
maxMessagesPerDay: j['maxMessagesPerDay'] as int?,
maxOrdersPerDay: j['maxOrdersPerDay'] as int?,
raw: j,
);
}