176 lines
4.9 KiB
Dart
176 lines
4.9 KiB
Dart
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
|
|
import 'package:brick_supabase/brick_supabase.dart';
|
|
|
|
enum NetworkImportFileKind {
|
|
pdf,
|
|
image,
|
|
vsdx,
|
|
csv,
|
|
xlsx,
|
|
docx,
|
|
other;
|
|
|
|
String get wire {
|
|
switch (this) {
|
|
case NetworkImportFileKind.pdf:
|
|
return 'pdf';
|
|
case NetworkImportFileKind.image:
|
|
return 'image';
|
|
case NetworkImportFileKind.vsdx:
|
|
return 'vsdx';
|
|
case NetworkImportFileKind.csv:
|
|
return 'csv';
|
|
case NetworkImportFileKind.xlsx:
|
|
return 'xlsx';
|
|
case NetworkImportFileKind.docx:
|
|
return 'docx';
|
|
case NetworkImportFileKind.other:
|
|
return 'other';
|
|
}
|
|
}
|
|
|
|
static NetworkImportFileKind fromExtension(String filename) {
|
|
final lower = filename.toLowerCase();
|
|
if (lower.endsWith('.pdf')) return NetworkImportFileKind.pdf;
|
|
if (lower.endsWith('.vsdx') || lower.endsWith('.vsd')) {
|
|
return NetworkImportFileKind.vsdx;
|
|
}
|
|
if (lower.endsWith('.csv')) return NetworkImportFileKind.csv;
|
|
if (lower.endsWith('.xlsx') || lower.endsWith('.xls')) {
|
|
return NetworkImportFileKind.xlsx;
|
|
}
|
|
if (lower.endsWith('.docx') || lower.endsWith('.doc')) {
|
|
return NetworkImportFileKind.docx;
|
|
}
|
|
if (lower.endsWith('.png') ||
|
|
lower.endsWith('.jpg') ||
|
|
lower.endsWith('.jpeg') ||
|
|
lower.endsWith('.webp') ||
|
|
lower.endsWith('.heic')) {
|
|
return NetworkImportFileKind.image;
|
|
}
|
|
return NetworkImportFileKind.other;
|
|
}
|
|
}
|
|
|
|
enum NetworkImportStatus {
|
|
pending,
|
|
extracting,
|
|
review,
|
|
applied,
|
|
discarded,
|
|
failed;
|
|
|
|
String get wire {
|
|
switch (this) {
|
|
case NetworkImportStatus.pending:
|
|
return 'pending';
|
|
case NetworkImportStatus.extracting:
|
|
return 'extracting';
|
|
case NetworkImportStatus.review:
|
|
return 'review';
|
|
case NetworkImportStatus.applied:
|
|
return 'applied';
|
|
case NetworkImportStatus.discarded:
|
|
return 'discarded';
|
|
case NetworkImportStatus.failed:
|
|
return 'failed';
|
|
}
|
|
}
|
|
|
|
static NetworkImportStatus fromWire(String? value) {
|
|
switch (value) {
|
|
case 'extracting':
|
|
return NetworkImportStatus.extracting;
|
|
case 'review':
|
|
return NetworkImportStatus.review;
|
|
case 'applied':
|
|
return NetworkImportStatus.applied;
|
|
case 'discarded':
|
|
return NetworkImportStatus.discarded;
|
|
case 'failed':
|
|
return NetworkImportStatus.failed;
|
|
default:
|
|
return NetworkImportStatus.pending;
|
|
}
|
|
}
|
|
}
|
|
|
|
@ConnectOfflineFirstWithSupabase(
|
|
supabaseConfig: SupabaseSerializable(tableName: 'network_imports'),
|
|
)
|
|
class NetworkImport extends OfflineFirstWithSupabaseModel {
|
|
final String id;
|
|
final String storagePath;
|
|
final NetworkImportFileKind fileKind;
|
|
final NetworkImportStatus status;
|
|
final Map<String, dynamic>? aiResult;
|
|
final String? errorMessage;
|
|
final List<String> appliedDeviceIds;
|
|
final List<String> appliedLinkIds;
|
|
final DateTime? appliedAt;
|
|
final String createdBy;
|
|
final DateTime createdAt;
|
|
|
|
NetworkImport({
|
|
required this.id,
|
|
required this.storagePath,
|
|
required this.fileKind,
|
|
required this.status,
|
|
this.aiResult,
|
|
this.errorMessage,
|
|
this.appliedDeviceIds = const [],
|
|
this.appliedLinkIds = const [],
|
|
this.appliedAt,
|
|
required this.createdBy,
|
|
required this.createdAt,
|
|
});
|
|
|
|
factory NetworkImport.fromMap(Map<String, dynamic> map) {
|
|
List<String> idList(dynamic raw) {
|
|
if (raw is List) {
|
|
return raw.map((v) => v.toString()).toList();
|
|
}
|
|
return const [];
|
|
}
|
|
|
|
return NetworkImport(
|
|
id: map['id'] as String,
|
|
storagePath: (map['storage_path'] as String?) ?? '',
|
|
fileKind: _fileKindFromWire(map['file_kind'] as String?),
|
|
status: NetworkImportStatus.fromWire(map['status'] as String?),
|
|
aiResult: map['ai_result'] is Map<String, dynamic>
|
|
? map['ai_result'] as Map<String, dynamic>
|
|
: null,
|
|
errorMessage: map['error_message'] as String?,
|
|
appliedDeviceIds: idList(map['applied_device_ids']),
|
|
appliedLinkIds: idList(map['applied_link_ids']),
|
|
appliedAt: map['applied_at'] == null
|
|
? null
|
|
: DateTime.tryParse(map['applied_at']?.toString() ?? ''),
|
|
createdBy: map['created_by'] as String,
|
|
createdAt:
|
|
DateTime.tryParse(map['created_at']?.toString() ?? '') ?? DateTime.now(),
|
|
);
|
|
}
|
|
|
|
static NetworkImportFileKind _fileKindFromWire(String? value) {
|
|
switch (value) {
|
|
case 'pdf':
|
|
return NetworkImportFileKind.pdf;
|
|
case 'image':
|
|
return NetworkImportFileKind.image;
|
|
case 'vsdx':
|
|
return NetworkImportFileKind.vsdx;
|
|
case 'csv':
|
|
return NetworkImportFileKind.csv;
|
|
case 'xlsx':
|
|
return NetworkImportFileKind.xlsx;
|
|
case 'docx':
|
|
return NetworkImportFileKind.docx;
|
|
default:
|
|
return NetworkImportFileKind.other;
|
|
}
|
|
}
|
|
}
|