88 lines
2.6 KiB
Dart
88 lines
2.6 KiB
Dart
import '../../models/subscription.dart';
|
|
import 'sms_scan_result.dart';
|
|
|
|
class SubscriptionConverter {
|
|
// SubscriptionModel 리스트를 Subscription 리스트로 변환
|
|
List<Subscription> convertResultsToSubscriptions(
|
|
List<SmsScanResult> results) {
|
|
final result = <Subscription>[];
|
|
|
|
for (final smsResult in results) {
|
|
try {
|
|
final subscription = _convertSingle(smsResult);
|
|
result.add(subscription);
|
|
|
|
// 개발 편의를 위한 디버그 로그
|
|
// ignore: avoid_print
|
|
print(
|
|
'모델 변환 성공: ${smsResult.model.serviceName}, 카테고리ID: ${smsResult.model.categoryId}, URL: ${smsResult.model.websiteUrl}, 통화: ${smsResult.model.currency}');
|
|
} catch (e) {
|
|
// ignore: avoid_print
|
|
print('모델 변환 중 오류 발생: $e');
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// 단일 모델 변환
|
|
Subscription _convertSingle(SmsScanResult result) {
|
|
final model = result.model;
|
|
return Subscription(
|
|
id: model.id,
|
|
serviceName: model.serviceName,
|
|
monthlyCost: model.monthlyCost,
|
|
billingCycle: _denormalizeBillingCycle(model.billingCycle), // 영어 -> 한국어
|
|
nextBillingDate: model.nextBillingDate,
|
|
category: model.categoryId, // categoryId를 category로 매핑
|
|
repeatCount: model.repeatCount > 0 ? model.repeatCount : 1,
|
|
lastPaymentDate: model.lastPaymentDate,
|
|
websiteUrl: model.websiteUrl,
|
|
currency: model.currency,
|
|
paymentCardId: model.paymentCardId,
|
|
paymentCardSuggestion: result.cardSuggestion,
|
|
);
|
|
}
|
|
|
|
// billingCycle 역정규화 (영어 -> 한국어)
|
|
String _denormalizeBillingCycle(String cycle) {
|
|
switch (cycle.toLowerCase()) {
|
|
case 'monthly':
|
|
return '월간';
|
|
case 'yearly':
|
|
case 'annually':
|
|
return '연간';
|
|
case 'weekly':
|
|
return '주간';
|
|
case 'daily':
|
|
return '일간';
|
|
case 'quarterly':
|
|
return '분기별';
|
|
case 'semi-annually':
|
|
return '반기별';
|
|
default:
|
|
return cycle; // 알 수 없는 형식은 그대로 반환
|
|
}
|
|
}
|
|
|
|
// billingCycle 정규화 (한국어 -> 영어)
|
|
String normalizeBillingCycle(String cycle) {
|
|
switch (cycle) {
|
|
case '월간':
|
|
return 'monthly';
|
|
case '연간':
|
|
return 'yearly';
|
|
case '주간':
|
|
return 'weekly';
|
|
case '일간':
|
|
return 'daily';
|
|
case '분기별':
|
|
return 'quarterly';
|
|
case '반기별':
|
|
return 'semi-annually';
|
|
default:
|
|
return 'monthly'; // 기본값
|
|
}
|
|
}
|
|
}
|