import '../../models/document_model.dart'; enum PollOutcomeKind { done, failed, pending } /// Result of inspecting a single `GET /documents/:id` poll response. /// Deliberately separated from the Dio call site /// (`pending_documents_provider.dart`'s `_pollUntilParsed`) so the /// parse-status branching is unit-testable without mocking network I/O - /// mirrors the pure-function pattern already used for `document_sync_merge.dart` /// (task 6.2) and `product_scan_response_parser.dart` (task 7.1). class PollOutcome { final PollOutcomeKind kind; final DocumentModel? document; final String? message; const PollOutcome._(this.kind, {this.document, this.message}); factory PollOutcome.done(DocumentModel document) => PollOutcome._(PollOutcomeKind.done, document: document); factory PollOutcome.failed(String message) => PollOutcome._(PollOutcomeKind.failed, message: message); static const PollOutcome pending = PollOutcome._(PollOutcomeKind.pending); } /// `parseStatus` absent/unrecognized (a legacy/cached response predating /// backend task 9.1) is treated the same as `"pending"` - keep polling rather /// than surface a false failure. PollOutcome resolvePollOutcome(DocumentModel fetched) { switch (fetched.parseStatus) { case 'done': return PollOutcome.done(fetched); case 'failed': return PollOutcome.failed('Gagal mengekstrak data (parsing gagal di server).'); default: return PollOutcome.pending; } }