import 'package:doctor_app_flutter/client/base_app_client.dart';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:flutter/cupertino.dart';
import '../models/doctor/list_doctor_working_hours_table_model.dart';
import '../models/doctor/request_schedule.dart';

class ScheduleProvider with ChangeNotifier {
  List<ListDoctorWorkingHoursTable> listDoctorWorkingHoursTable = [];
  bool isLoading = true;
  bool isError = false;
  String error = '';
  RequestSchedule requestSchedule = RequestSchedule();

  ScheduleProvider() {
    getDoctorSchedule();
  }

  getDoctorSchedule() async {
    try {
      await BaseAppClient.post(GET_DOCTOR_WORKING_HOURS_TABLE,
          body: requestSchedule.toJson(),
          onSuccess: (dynamic response, int statusCode) {
        response['List_DoctorWorkingHoursTable'].forEach((v) {
          listDoctorWorkingHoursTable.add(new ListDoctorWorkingHoursTable.fromJson(v));
        });
        isError = false;
        isLoading = false;
      }, onFailure: (String error, int statusCode) {
        isLoading = false;
        isError = true;
        this.error = error;
      });
      notifyListeners();
    } catch (e) {
      isLoading = false;
      isError = true;
      error = 'Something wrong happened, please contact the admin';
      notifyListeners();
    }
  }
}
