- ExchangeRateService에 JPY, CNY 환율 지원 추가 - 구독 서비스별 다국어 표시 이름 지원 - 분석 화면 차트 및 UI/UX 개선 - 설정 화면 전면 리팩토링 - SMS 스캔 기능 사용성 개선 - 전체 앱 다국어 번역 확대 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
131 lines
3.1 KiB
Dart
131 lines
3.1 KiB
Dart
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
part 'subscription_model.g.dart';
|
|
|
|
@HiveType(typeId: 0)
|
|
class SubscriptionModel extends HiveObject {
|
|
@HiveField(0)
|
|
final String id;
|
|
|
|
@HiveField(1)
|
|
String serviceName;
|
|
|
|
@HiveField(2)
|
|
double monthlyCost;
|
|
|
|
@HiveField(3)
|
|
String billingCycle; // 'monthly', 'yearly', 'weekly' - 영어 키값 사용
|
|
|
|
@HiveField(4)
|
|
DateTime nextBillingDate;
|
|
|
|
@HiveField(5)
|
|
bool isAutoDetected; // SMS로 추가된 경우 true
|
|
|
|
@HiveField(6)
|
|
String? categoryId;
|
|
|
|
@HiveField(7)
|
|
String? websiteUrl; // 홈페이지 URL
|
|
|
|
@HiveField(8)
|
|
int repeatCount; // 반복 결제 횟수
|
|
|
|
@HiveField(9)
|
|
DateTime? lastPaymentDate; // 마지막 결제일
|
|
|
|
@HiveField(10)
|
|
String currency; // 통화 단위: 'KRW' 또는 'USD'
|
|
|
|
@HiveField(11)
|
|
bool isEventActive; // 이벤트 활성화 여부
|
|
|
|
@HiveField(12)
|
|
DateTime? eventStartDate; // 이벤트 시작일
|
|
|
|
@HiveField(13)
|
|
DateTime? eventEndDate; // 이벤트 종료일
|
|
|
|
@HiveField(14)
|
|
double? eventPrice; // 이벤트 기간 중 가격
|
|
|
|
SubscriptionModel({
|
|
required this.id,
|
|
required this.serviceName,
|
|
required this.monthlyCost,
|
|
required this.billingCycle,
|
|
required this.nextBillingDate,
|
|
this.isAutoDetected = false,
|
|
this.categoryId,
|
|
this.websiteUrl,
|
|
this.repeatCount = 1,
|
|
this.lastPaymentDate,
|
|
this.currency = 'KRW', // 기본값은 KRW
|
|
this.isEventActive = false, // 기본값은 false
|
|
this.eventStartDate,
|
|
this.eventEndDate,
|
|
this.eventPrice,
|
|
});
|
|
|
|
// 주기적 결제 여부 확인
|
|
bool get isRecurring => repeatCount > 1;
|
|
|
|
// 현재 이벤트 기간인지 확인
|
|
bool get isCurrentlyInEvent {
|
|
if (!isEventActive || eventStartDate == null || eventEndDate == null) {
|
|
return false;
|
|
}
|
|
|
|
final now = DateTime.now();
|
|
return now.isAfter(eventStartDate!) && now.isBefore(eventEndDate!);
|
|
}
|
|
|
|
// 현재 적용되는 가격 (이벤트 또는 정상 가격)
|
|
double get currentPrice {
|
|
if (isCurrentlyInEvent && eventPrice != null) {
|
|
return eventPrice!;
|
|
}
|
|
return monthlyCost;
|
|
}
|
|
|
|
// 이벤트로 인한 절약액
|
|
double get eventSavings {
|
|
if (isCurrentlyInEvent && eventPrice != null) {
|
|
return monthlyCost - eventPrice!;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// 원래 가격 (이벤트와 관계없이 항상 정상 가격)
|
|
double get originalPrice => monthlyCost;
|
|
|
|
// 결제 주기를 영어 키값으로 정규화
|
|
static String normalizeBillingCycle(String cycle) {
|
|
switch (cycle.toLowerCase()) {
|
|
case 'monthly':
|
|
case '월간':
|
|
case '月間':
|
|
case '月付':
|
|
return 'monthly';
|
|
case 'weekly':
|
|
case '주간':
|
|
case '週間':
|
|
case '周付':
|
|
return 'weekly';
|
|
case 'yearly':
|
|
case '연간':
|
|
case '年間':
|
|
case '年付':
|
|
return 'yearly';
|
|
default:
|
|
return 'monthly'; // 기본값은 monthly
|
|
}
|
|
}
|
|
|
|
// 결제 주기를 영어 키값으로 반환 (내부 사용)
|
|
String get billingCycleKey => normalizeBillingCycle(billingCycle);
|
|
}
|
|
|
|
// Hive TypeAdapter 생성을 위한 명령어
|
|
// flutter pub run build_runner build
|