//import 'dart' as dart; import 'dart:io'; /// This class holds all the data collected across the multi-step tarball sampling form. /// It acts as a temporary data container that is passed between screens. class TarballSamplingData { // --- Step 1 Data: Collected in TarballSamplingStep1 --- String? firstSampler; int? firstSamplerUserId; Map? secondSampler; // Holds the full user map for the 2nd sampler String? samplingDate; String? samplingTime; String? selectedStateName; String? selectedCategoryName; Map? selectedStation; // Holds the full station map String? stationLatitude; String? stationLongitude; String? currentLatitude; String? currentLongitude; double? distanceDifference; String? distanceDifferenceRemarks; // --- Step 2 Data: Collected in TarballSamplingStep2 --- int? classificationId; // NECESSARY CHANGE: Add property to hold the full classification object. Map? selectedClassification; File? leftCoastalViewImage; File? rightCoastalViewImage; File? verticalLinesImage; File? horizontalLineImage; File? optionalImage1; String? optionalRemark1; File? optionalImage2; String? optionalRemark2; File? optionalImage3; String? optionalRemark3; File? optionalImage4; String? optionalRemark4; // --- Step 3 Data: For handling the submission response --- String? reportId; String? submissionStatus; String? submissionMessage; /// Generates a formatted Telegram alert message for successful submissions. String generateTelegramAlertMessage({required bool isDataOnly}) { final submissionType = isDataOnly ? "(Data Only)" : "(Data & Images)"; final stationName = selectedStation?['tbl_station_name'] ?? 'N/A'; final stationCode = selectedStation?['tbl_station_code'] ?? 'N/A'; // This logic now correctly uses the full classification object if available. final classification = selectedClassification?['classification_name'] ?? classificationId?.toString() ?? 'N/A'; final buffer = StringBuffer() ..writeln('✅ *Tarball Sample $submissionType Submitted:*') ..writeln() ..writeln('*Station Name & Code:* $stationName ($stationCode)') ..writeln('*Date of Submission:* $samplingDate') ..writeln('*Submitted by User:* $firstSampler') ..writeln('*Classification:* $classification') ..writeln('*Status of Submission:* Successful'); // Add distance alert if relevant if (distanceDifference != null && distanceDifference! > 0) { buffer ..writeln() ..writeln('🔔 *Alert:*') ..writeln('*Distance from station:* ${(distanceDifference! * 1000).toStringAsFixed(0)} meters'); if (distanceDifferenceRemarks != null && distanceDifferenceRemarks!.isNotEmpty) { buffer.writeln('*Remarks for distance:* $distanceDifferenceRemarks'); } } return buffer.toString(); } /// Converts the form's text and selection data into a Map suitable for JSON encoding. /// This map will be sent as the body of the first API request. Map toFormData() { final Map data = { // Required fields 'station_id': selectedStation?['station_id']?.toString() ?? '', 'sampling_date': samplingDate ?? '', 'sampling_time': samplingTime ?? '', // User ID fields 'first_sampler_user_id': firstSamplerUserId?.toString() ?? '', 'second_sampler_user_id': secondSampler?['user_id']?.toString() ?? '', // Foreign Key ID for classification 'classification_id': classificationId?.toString() ?? '', // Other nullable fields 'current_latitude': currentLatitude ?? '', 'current_longitude': currentLongitude ?? '', 'distance_difference': distanceDifference?.toString() ?? '', 'optional_photo_remark_01': optionalRemark1 ?? '', 'optional_photo_remark_02': optionalRemark2 ?? '', 'optional_photo_remark_03': optionalRemark3 ?? '', 'optional_photo_remark_04': optionalRemark4 ?? '', 'distance_remarks': distanceDifferenceRemarks ?? '', // Human-readable names for the Telegram alert 'tbl_station_name': selectedStation?['tbl_station_name']?.toString() ?? '', 'tbl_station_code': selectedStation?['tbl_station_code']?.toString() ?? '', 'first_sampler_name': firstSampler ?? '', // NECESSARY CHANGE: Add the classification name for the alert. 'classification_name': selectedClassification?['classification_name']?.toString() ?? '', }; return data; } /// Gathers all non-null image files into a Map. /// This map is used to build the multipart request for the second API call (image upload). Map toImageFiles() { return { 'left_side_coastal_view': leftCoastalViewImage, 'right_side_coastal_view': rightCoastalViewImage, 'drawing_vertical_lines': verticalLinesImage, 'drawing_horizontal_line': horizontalLineImage, 'optional_photo_01': optionalImage1, 'optional_photo_02': optionalImage2, 'optional_photo_03': optionalImage3, 'optional_photo_04': optionalImage4, }; } }