import 'package:get/get.dart';
import 'package:on_field_work/helpers/services/api_service.dart'; 
import 'package:on_field_work/model/infra_project/infra_project_details.dart';

class InfraProjectDetailsController extends GetxController {
  final String projectId;

  InfraProjectDetailsController({required this.projectId});

  var isLoading = true.obs;
  var projectDetails = Rxn<ProjectData>();
  var errorMessage = ''.obs;

  @override
  void onInit() {
    super.onInit();
    fetchProjectDetails();
  }

  Future<void> fetchProjectDetails() async {
    try {
      isLoading.value = true;
      final response = await ApiService.getInfraProjectDetails(projectId: projectId);

      if (response != null && response.success == true && response.data != null) {
        projectDetails.value = response.data;
        isLoading.value = false;

      } else {
        errorMessage.value = response?.message ?? "Failed to load project details";
      }
    } catch (e) {
      errorMessage.value = "Error fetching project details: $e";
    } finally {
      isLoading.value = false;
    }
  }
}
