Files
submanager/lib/models/subscription.dart
2025-11-14 16:53:41 +09:00

83 lines
2.6 KiB
Dart

import 'payment_card_suggestion.dart';
class Subscription {
final String id;
final String serviceName;
final double monthlyCost;
final String billingCycle;
final DateTime nextBillingDate;
final String? category;
final String? notes;
final int repeatCount;
final DateTime? lastPaymentDate;
final String? websiteUrl;
final String currency;
final String? paymentCardId;
final PaymentCardSuggestion? paymentCardSuggestion;
Subscription({
required this.id,
required this.serviceName,
required this.monthlyCost,
required this.billingCycle,
required this.nextBillingDate,
this.category,
this.notes,
this.repeatCount = 1,
this.lastPaymentDate,
this.websiteUrl,
this.currency = 'KRW',
this.paymentCardId,
this.paymentCardSuggestion,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'serviceName': serviceName,
'monthlyCost': monthlyCost,
'billingCycle': billingCycle,
'nextBillingDate': nextBillingDate.toIso8601String(),
'category': category,
'notes': notes,
'repeatCount': repeatCount,
'lastPaymentDate': lastPaymentDate?.toIso8601String(),
'websiteUrl': websiteUrl,
'currency': currency,
'paymentCardId': paymentCardId,
'paymentCardSuggestionIssuer': paymentCardSuggestion?.issuerName,
'paymentCardSuggestionLast4': paymentCardSuggestion?.last4,
'paymentCardSuggestionSource': paymentCardSuggestion?.source,
};
}
factory Subscription.fromMap(Map<String, dynamic> map) {
return Subscription(
id: map['id'] as String,
serviceName: map['serviceName'] as String,
monthlyCost: map['monthlyCost'] as double,
billingCycle: map['billingCycle'] as String,
nextBillingDate: DateTime.parse(map['nextBillingDate'] as String),
category: map['category'] as String?,
notes: map['notes'] as String?,
repeatCount: (map['repeatCount'] as num?)?.toInt() ?? 1,
lastPaymentDate: map['lastPaymentDate'] != null
? DateTime.parse(map['lastPaymentDate'] as String)
: null,
websiteUrl: map['websiteUrl'] as String?,
currency: map['currency'] as String? ?? 'KRW',
paymentCardId: map['paymentCardId'] as String?,
paymentCardSuggestion: map['paymentCardSuggestionIssuer'] != null
? PaymentCardSuggestion(
issuerName: map['paymentCardSuggestionIssuer'] as String,
last4: map['paymentCardSuggestionLast4'] as String?,
source: map['paymentCardSuggestionSource'] as String?,
)
: null,
);
}
// 주기적 결제 여부 확인
bool get isRecurring => repeatCount > 1;
}