feat(boxing): handle multi-code paichan switches
This commit is contained in:
38
lib/services/boxing_context.dart
Normal file
38
lib/services/boxing_context.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
enum PaichanContextChange { firstScan, samePaichan, switchedPaichan }
|
||||
|
||||
class PaichanContextDecision {
|
||||
final PaichanContextChange change;
|
||||
final int? boxNoToApply;
|
||||
|
||||
const PaichanContextDecision({required this.change, this.boxNoToApply});
|
||||
|
||||
bool get isSwitched => change == PaichanContextChange.switchedPaichan;
|
||||
}
|
||||
|
||||
PaichanContextDecision decideMultiCodePaichanContext({
|
||||
required String? lastPaichanNo,
|
||||
required String? currentPaichanNo,
|
||||
required String currentBoxNoText,
|
||||
required int maxBoxNo,
|
||||
}) {
|
||||
final recommendedBoxNo = maxBoxNo + 1;
|
||||
if (currentPaichanNo == null || currentPaichanNo.isEmpty) {
|
||||
return const PaichanContextDecision(change: PaichanContextChange.firstScan);
|
||||
}
|
||||
if (lastPaichanNo == null || lastPaichanNo.isEmpty) {
|
||||
return PaichanContextDecision(
|
||||
change: PaichanContextChange.firstScan,
|
||||
boxNoToApply: currentBoxNoText.trim().isEmpty ? recommendedBoxNo : null,
|
||||
);
|
||||
}
|
||||
if (lastPaichanNo == currentPaichanNo) {
|
||||
return PaichanContextDecision(
|
||||
change: PaichanContextChange.samePaichan,
|
||||
boxNoToApply: currentBoxNoText.trim().isEmpty ? recommendedBoxNo : null,
|
||||
);
|
||||
}
|
||||
return PaichanContextDecision(
|
||||
change: PaichanContextChange.switchedPaichan,
|
||||
boxNoToApply: recommendedBoxNo,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user