import 'package:get/get.dart';
import 'package:hallo_doctor_client/app/models/doctor_model.dart';
import 'package:hallo_doctor_client/app/models/review_model.dart';
import 'package:hallo_doctor_client/app/service/review_service.dart';

class ListReviewController extends GetxController
    with StateMixin<List<ReviewModel>> {
  final ReviewService _reviewService = Get.find<ReviewService>();
  final Doctor doctor = Get.arguments;
  final reviews = <ReviewModel>[].obs;

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

  Future<void> fetchReviews() async {
    try {
      change(null, status: RxStatus.loading());

      final reviewList = await _reviewService.getDoctorReview(
        doctor: doctor,
        limit: 50, // Get more reviews for the list view
      );

      if (reviewList.isEmpty) {
        change([], status: RxStatus.empty());
      } else {
        reviews.value = reviewList;
        change(reviewList, status: RxStatus.success());
      }
    } catch (error) {
      change(null, status: RxStatus.error('Failed to load reviews'));
    }
  }

  Future<void> refreshReviews() async {
    return fetchReviews();
  }
}
