import "dart:typed_data"; import "../config/api_config.dart"; import "../models/photo.dart"; import "api_client.dart"; import "mock_data.dart"; class PhotoService { final ApiClient _client; PhotoService(this._client); Future> fetchPhotos({bool activeOnly = false}) async { if (ApiConfig.useMockData) { final items = List.from(MockDataStore.photos); if (activeOnly) { return items.where((item) => item.active).toList(); } return items; } final query = activeOnly ? {"active": "true"} : null; final data = await _client.getList(ApiConfig.photos, query: query); return data .map((item) => Photo.fromJson(item as Map)) .toList(); } Future createPhoto(Photo photo) async { if (ApiConfig.useMockData) { final created = Photo( id: "photo-${DateTime.now().millisecondsSinceEpoch}", url: photo.url, caption: photo.caption, active: photo.active, ); MockDataStore.photos.add(created); return created; } final data = await _client.post(ApiConfig.photos, photo.toJson()); return Photo.fromJson(data); } Future uploadPhotoBytes({ required Uint8List bytes, required String filename, String caption = "", bool active = true, }) async { if (ApiConfig.useMockData) { final created = Photo( id: "photo-${DateTime.now().millisecondsSinceEpoch}", url: "mock://$filename", caption: caption, active: active, ); MockDataStore.photos.add(created); return created; } final data = await _client.postMultipart( "${ApiConfig.photos}/upload", fieldName: "file", bytes: bytes, filename: filename, fields: { "caption": caption, "active": active.toString(), }, ); return Photo.fromJson(data); } Future deletePhoto(String id) async { if (ApiConfig.useMockData) { MockDataStore.photos.removeWhere((item) => item.id == id); return; } await _client.delete("${ApiConfig.photos}/$id"); } Future getGoogleAuthUrl() async { final data = await _client.getMap("${ApiConfig.photos}/auth/url"); return data["url"] as String; } Future getGoogleStatus() async { try { final data = await _client.getMap("${ApiConfig.photos}/status"); return data["connected"] as bool? ?? false; } catch (e) { return false; } } Future disconnectGoogle() async { await _client.getMap("${ApiConfig.photos}/disconnect"); } }