77 lines
2.0 KiB
Dart
77 lines
2.0 KiB
Dart
import 'package:isar/isar.dart';
|
|
|
|
import '../../../core/constants/app_defaults.dart';
|
|
|
|
part 'app_config.g.dart';
|
|
|
|
enum EntitlementSource {
|
|
none,
|
|
purchase,
|
|
restore,
|
|
}
|
|
|
|
@collection
|
|
class AppConfig {
|
|
AppConfig();
|
|
|
|
Id id = AppDefaults.singletonId;
|
|
|
|
@Index(unique: true, replace: true)
|
|
late String configKey;
|
|
|
|
@Index(type: IndexType.value)
|
|
late DateTime updatedAt;
|
|
|
|
late DateTime createdAt;
|
|
int freeTrialLimit = AppDefaults.defaultFreeTrialLimit;
|
|
int usedTrialCount = 0;
|
|
bool isVipUnlocked = false;
|
|
DateTime? vipUnlockedAt;
|
|
String? lastIapErrorMessage;
|
|
|
|
@enumerated
|
|
EntitlementSource entitlementSource = EntitlementSource.none;
|
|
|
|
factory AppConfig.createDefault({DateTime? now}) {
|
|
final current = now ?? DateTime.now();
|
|
|
|
return AppConfig()
|
|
..configKey = 'local_app_config'
|
|
..createdAt = current
|
|
..updatedAt = current
|
|
..freeTrialLimit = AppDefaults.defaultFreeTrialLimit
|
|
..usedTrialCount = 0
|
|
..isVipUnlocked = false
|
|
..entitlementSource = EntitlementSource.none;
|
|
}
|
|
|
|
int get remainingTrialCount {
|
|
final remaining = freeTrialLimit - usedTrialCount;
|
|
return remaining > 0 ? remaining : 0;
|
|
}
|
|
|
|
bool get canStartScoring => isVipUnlocked || usedTrialCount < freeTrialLimit;
|
|
|
|
AppConfig copyWith({
|
|
int? freeTrialLimit,
|
|
int? usedTrialCount,
|
|
bool? isVipUnlocked,
|
|
DateTime? vipUnlockedAt,
|
|
String? lastIapErrorMessage,
|
|
EntitlementSource? entitlementSource,
|
|
DateTime? updatedAt,
|
|
}) {
|
|
return AppConfig()
|
|
..id = id
|
|
..configKey = configKey
|
|
..createdAt = createdAt
|
|
..updatedAt = updatedAt ?? DateTime.now()
|
|
..freeTrialLimit = freeTrialLimit ?? this.freeTrialLimit
|
|
..usedTrialCount = usedTrialCount ?? this.usedTrialCount
|
|
..isVipUnlocked = isVipUnlocked ?? this.isVipUnlocked
|
|
..vipUnlockedAt = vipUnlockedAt ?? this.vipUnlockedAt
|
|
..lastIapErrorMessage = lastIapErrorMessage ?? this.lastIapErrorMessage
|
|
..entitlementSource = entitlementSource ?? this.entitlementSource;
|
|
}
|
|
}
|