import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/H2O/insert_user_activity_request_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/H2O/user_progress_for_month_data_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/H2O/user_progress_for_today_data_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/H2O/user_progress_for_week_data_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/H2O/user_progress_request_model.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';

class H2OService extends BaseService {
  List<UserProgressForTodayDataModel> userProgressForTodayDataList = List();
  List<UserProgressForWeekDataModel> userProgressForWeekDataList = List();
  List<UserProgressForMonthDataModel> userProgressForMonthDataList = List();
  UserProgressRequestModel userProgressRequestModel =
      UserProgressRequestModel();

  Future getUserProgressForTodayData() async {
    userProgressRequestModel.progress = 1;
    userProgressRequestModel.mobileNumber = user.mobileNumber.substring(1);
    userProgressRequestModel.identificationNo = user.patientIdentificationNo;

    hasError = false;
    await baseAppClient.post(H2O_GET_USER_PROGRESS,
        onSuccess: (dynamic response, int statusCode) {
      userProgressForTodayDataList.clear();
      response['UserProgressForTodayData'].forEach((progressData) {
        userProgressForTodayDataList
            .add(UserProgressForTodayDataModel.fromJson(progressData));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: userProgressRequestModel.toJson());
  }

  Future getUserProgressForWeekData() async {
    userProgressRequestModel.progress = 2;
    userProgressRequestModel.mobileNumber = super.user.mobileNumber.substring(1);
    userProgressRequestModel.identificationNo = super.user.patientIdentificationNo;

    hasError = false;
    await baseAppClient.post(H2O_GET_USER_PROGRESS,
        onSuccess: (dynamic response, int statusCode) {
          userProgressForTodayDataList.clear();
          response['UserProgressForWeekData'].forEach((hospital) {
            userProgressForWeekDataList.add(UserProgressForWeekDataModel.fromJson(hospital));
          });
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: userProgressRequestModel.toJson());
  }

  Future getUserProgressForMonthData() async {
    userProgressRequestModel.progress = 3;
    userProgressRequestModel.mobileNumber = super.user.mobileNumber.substring(1);
    userProgressRequestModel.identificationNo = super.user.patientIdentificationNo;

    hasError = false;
    await baseAppClient.post(H2O_GET_USER_PROGRESS,
    onSuccess: (dynamic response, int statusCode) {
      userProgressForMonthDataList.clear();
      response['UserProgressForMonthData'].forEach((hospital) {
        userProgressForMonthDataList.add(UserProgressForMonthDataModel.fromJson(hospital));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: userProgressRequestModel.toJson());
  }




  Future insertUserActivity(InsertUserActivityRequestModel insertUserActivityRequestModel) async {

    hasError = false;
    await baseAppClient.post(H2O_INSERT_USER_ACTIVITY,
        onSuccess: (dynamic response, int statusCode) {
          userProgressForTodayDataList.clear();
          response['UserProgressForTodayData'].forEach((progressData) {
            userProgressForTodayDataList
                .add(UserProgressForTodayDataModel.fromJson(progressData));
          });
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: insertUserActivityRequestModel.toJson());
  }
}
