import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/Prescriptions.dart';

class PrescriptionService extends BaseService {
  final AppSharedPreferences sharedPref = AppSharedPreferences();
  bool isFinished = true;
  bool hasError = false;
  String errorMsg = '';
  String url = "";

  List<Prescriptions> _prescriptionsList = List();
  List<Prescriptions> get prescriptionsList => _prescriptionsList;

//  Future getPrescription() async {
//    hasError = false;
//    url = PRESCRIPTION;
//    print("Print PRESCRIPTION url" + url);
//    await baseAppClient.get(url,
//        onSuccess: (dynamic response, int statusCode) {
//          _prescriptionsList.clear();
//          response['PatientPrescriptionList'].forEach((item) {
//            _prescriptionsList.add(Prescriptions.fromJson(item));
//          });
//          print(_prescriptionsList.length);
//          print(response);
//        }, onFailure: (String error, int statusCode) {
//          hasError = true;
//          super.error = error;
//        });
//  }
  Future getPrescription() async {
    url = PRESCRIPTION;
    print("Print PRESCRIPTION url" + url);
    hasError = false;
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    print("Print PRESCRIPTION url" + url);
    await baseAppClient.post(url,
        onSuccess: (dynamic response, int statusCode) {
      _prescriptionsList.clear();
      response['PatientPrescriptionList'].forEach((prescriptions) {
        _prescriptionsList.add(Prescriptions.fromJson(prescriptions));
      });
      print(_prescriptionsList.length);
      print("response is -------------"+response);
      print(response);
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
