import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart'; import 'package:brick_supabase/brick_supabase.dart'; enum NetworkLocationKind { building, floor, room, rack, wallJack, other; String get wire { switch (this) { case NetworkLocationKind.building: return 'building'; case NetworkLocationKind.floor: return 'floor'; case NetworkLocationKind.room: return 'room'; case NetworkLocationKind.rack: return 'rack'; case NetworkLocationKind.wallJack: return 'wall_jack'; case NetworkLocationKind.other: return 'other'; } } static NetworkLocationKind fromWire(String? value) { switch (value) { case 'building': return NetworkLocationKind.building; case 'floor': return NetworkLocationKind.floor; case 'room': return NetworkLocationKind.room; case 'rack': return NetworkLocationKind.rack; case 'wall_jack': return NetworkLocationKind.wallJack; default: return NetworkLocationKind.other; } } } @ConnectOfflineFirstWithSupabase( supabaseConfig: SupabaseSerializable(tableName: 'network_locations'), ) class NetworkLocation extends OfflineFirstWithSupabaseModel { final String id; final String siteId; final String? parentId; final String name; final NetworkLocationKind kind; final String? positionLabel; final String? notes; final DateTime createdAt; NetworkLocation({ required this.id, required this.siteId, this.parentId, required this.name, required this.kind, this.positionLabel, this.notes, required this.createdAt, }); factory NetworkLocation.fromMap(Map map) { return NetworkLocation( id: map['id'] as String, siteId: map['site_id'] as String, parentId: map['parent_id'] as String?, name: (map['name'] as String?) ?? '', kind: NetworkLocationKind.fromWire(map['kind'] as String?), positionLabel: map['position_label'] as String?, notes: map['notes'] as String?, createdAt: DateTime.tryParse(map['created_at']?.toString() ?? '') ?? DateTime.now(), ); } Map toInsertMap() => { 'site_id': siteId, if (parentId != null) 'parent_id': parentId, 'name': name, 'kind': kind.wire, if (positionLabel != null) 'position_label': positionLabel, if (notes != null) 'notes': notes, }; }