import 'package:dartz/dartz.dart';
import 'package:hmg_patient_app_new/core/api/api_client.dart';
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';

abstract class BookAppointmentsRepo {
  Future<Either<Failure, dynamic>> getDoctors();
}

class BookAppointmentsRepoImp implements BookAppointmentsRepo {
  final ApiClient apiClient;
  final LoggerService loggerService;

  BookAppointmentsRepoImp({required this.loggerService, required this.apiClient});

  @override
  Future<Either<Failure, dynamic>> getDoctors() async {
    try {
      // Mock API call with delayed response
      final result = await Future.delayed(
        const Duration(seconds: 2),
        () => {
          'success': true,
          'data': [
            {
              'id': '1',
              'name': 'Dr. Ahmed Hassan',
              'specialty': 'Cardiology',
              'experience': '10 years',
              'rating': 4.8,
              'image': 'https://example.com/doctor1.jpg'
            },
          ]
        }
      );

      if (result != null && result is Map && result['success'] != null && result['success'] != false) {
        return Right(result);
      } else {
        loggerService.errorLogs(result.toString());
        return Left(ServerFailure(result.toString()));
      }
    } catch (e) {
      loggerService.errorLogs(e.toString());
      return Left(ServerFailure(e.toString()));
    }
  }
}
