import 'package:get/get.dart'; import 'package:marco/helpers/services/api_service.dart'; import 'package:marco/model/document/document_details_model.dart'; import 'package:marco/model/document/document_version_model.dart'; class DocumentDetailsController extends GetxController { /// Observables var isLoading = false.obs; var documentDetails = Rxn(); var versions = [].obs; var isVersionsLoading = false.obs; /// Fetch document details by id Future fetchDocumentDetails(String documentId) async { try { isLoading.value = true; final response = await ApiService.getDocumentDetailsApi(documentId); if (response != null) { documentDetails.value = response; } else { documentDetails.value = null; } } finally { isLoading.value = false; } } /// Fetch document versions by parentAttachmentId Future fetchDocumentVersions(String parentAttachmentId) async { try { isVersionsLoading.value = true; final response = await ApiService.getDocumentVersionsApi( parentAttachmentId: parentAttachmentId, ); if (response != null) { versions.assignAll(response.data.data); } else { versions.clear(); } } finally { isVersionsLoading.value = false; } } /// Fetch Pre-Signed URL for a given version Future fetchPresignedUrl(String versionId) async { return await ApiService.getPresignedUrlApi(versionId); } /// Clear data when leaving the screen void clearDetails() { documentDetails.value = null; versions.clear(); } }