import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/core/model/doctor/list_doctor_working_hours_table_model.dart';
import 'package:doctor_app_flutter/core/model/doctor/request_schedule.dart';

import '../../../config/shared_pref_kay.dart';
import '../../model/dashboard/doctor_schedule.dart';

class ScheduleService extends BaseService {
  List<ListDoctorWorkingHoursTable> get listDoctorWorkingHoursTable =>
      _listDoctorWorkingHoursTable;
  List<ListDoctorWorkingHoursTable> _listDoctorWorkingHoursTable = [];

  RequestSchedule _requestSchedule = RequestSchedule();
  List<DoctorSchedule> _doctorRota= [];
  List<DoctorSchedule> get doctorRotation => _doctorRota;
  Future getDoctorSchedule() async {
    await baseAppClient.post(GET_DOCTOR_WORKING_HOURS_TABLE,
        onSuccess: (dynamic response, int statusCode) {
      _listDoctorWorkingHoursTable.clear();
      response['List_DoctorWorkingHoursTable'].forEach((v) {
        _listDoctorWorkingHoursTable
            .add(ListDoctorWorkingHoursTable.fromJson(v));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestSchedule.toJson(), isFallLanguage: true);
  }


  Future getDoctorRota(String fromDate, String toDate,{int pageNo = 1}) async{
    hasError = false;
    String doctorId =  await sharedPref.getString(DOCTOR_ID); ////'7826';
    String url = DOCTOR_SCHEDULE + '?userid='+doctorId+'&fromDate='+fromDate+'&toDate='+toDate+'&pagenumber='+pageNo.toString()+'&pagesize=10';
    await baseAppClient.get( endPoint: url, onSuccess: (dynamic response, int statusCode) {
      _doctorRota =[];

            response['response'].forEach((res){
        _doctorRota.add(DoctorSchedule.fromJson(res));
      });
      print(_doctorRota);
    }, onFailure: (String error, int statusCode) {
      print(error);
    },

    );
  }
}
