import 'package:get/get.dart';

class UploadProgressService extends GetxService {
  var isUploading = false.obs;
  var progress = 0.0.obs;
  var companyName = ''.obs;
  var totalImages = 0.obs;
  var currentImageIndex = 0.obs;
  var status = 'uploading'.obs; // uploading, processing, done

  void startUpload(String company, int total) {
    isUploading.value = true;
    companyName.value = company;
    totalImages.value = total;
    currentImageIndex.value = 0;
    progress.value = 0.0;
    status.value = 'uploading';
  }

  void updateProgress(double p, int current) {
    progress.value = p;
    currentImageIndex.value = current;
  }

  void startProcessing() {
    status.value = 'processing';
    progress.value = 0.5; // generic progress for processing until FCM hits
  }

  void updateProcessingProgress(int processed, int total) {
    status.value = 'processing';
    progress.value = processed / total;
    currentImageIndex.value = processed;
    totalImages.value = total;
  }

  void complete() {
    status.value = 'done';
    progress.value = 1.0;
    Future.delayed(const Duration(seconds: 3), () {
      isUploading.value = false;
    });
  }

  void fail() {
    isUploading.value = false;
  }
}
