import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/procedure/categories_procedure.dart';
import 'package:doctor_app_flutter/core/model/procedure/get_procedure_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/get_procedure_req_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:flutter/foundation.dart';

class ProcedureService extends BaseService {
  List<GetProcedureModel> _procedureList = List();
  List<GetProcedureModel> get procedureList => _procedureList;
  List<CategoriseProcedureModel> _categoriesList = List();
  List<CategoriseProcedureModel> get categoriesList => _categoriesList;
  List<Procedures> procedureslist = List();

  Procedures t1 = Procedures(
    category: '02',
    procedure: '02011002',
  );

  GetProcedureReqModel _getProcedureReqModel = GetProcedureReqModel(
    clinicId: 0,
    pageSize: 10,
    pageIndex: 1,
    patientMRN: 0,
    //categoryId: null,
    vidaAuthTokenID:
        "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxNDg1IiwianRpIjoiZjQ4YTk0OTQtYTczZS00MDI3LWI2MjgtNzc4MjAwMzUyYWEzIiwiZW1haWwiOiJNb2hhbWVkLlJlc3dhbkBjbG91ZHNvbHV0aW9uLXNhLmNvbSIsImlkIjoiMTQ4NSIsIk5hbWUiOiJTSEFLRVJBIFBBUlZFRU4gKFVTRUQgQlkgRVNFUlZJQ0VTKSIsIkVtcGxveWVlSWQiOiIxNDg1IiwiRmFjaWxpdHlHcm91cElkIjoiMDEwMjY2IiwiRmFjaWxpdHlJZCI6IjE1IiwiUGhhcmFtY3lGYWNpbGl0eUlkIjoiNTUiLCJJU19QSEFSTUFDWV9DT05ORUNURUQiOiJUcnVlIiwiRG9jdG9ySWQiOiIxNDg1IiwiU0VTU0lPTklEIjoiMjE1ODUyMTAiLCJDbGluaWNJZCI6IjMiLCJyb2xlIjoiRE9DVE9SUyIsIm5iZiI6MTYwODM2NDU2OCwiZXhwIjoxNjA5MjI4NTY4LCJpYXQiOjE2MDgzNjQ1Njh9.YLbvq5nxPn8o9ZYkcbc5YAX7Jy23Mm0s33oRmE8GHDI",

    search: ["lab"],
  );

  PostProcedureReqModel _postProcedureReqModel = PostProcedureReqModel();

  Future getProcedure() async {
    hasError = false;
    _procedureList.clear();
    await baseAppClient.post(GET_PROCEDURE_LIST,
        onSuccess: (dynamic response, int statusCode) {
      _procedureList.add(GetProcedureModel.fromJson(response['ProcedureList']));
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _getProcedureReqModel.toJson());
  }

  Future getCategories() async {
    hasError = false;
    _categoriesList.clear();
    await baseAppClient.post(
      GET_CATEGORISE_PROCEDURE,
      onSuccess: (dynamic response, int statusCode) {
        _categoriesList
            .add(CategoriseProcedureModel.fromJson(response['listCategories']));
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
    );
  }

  Future postProcedure(PostProcedureReqModel postProcedureReqModel) async {
    hasError = false;
    _procedureList.clear();
    await baseAppClient.post(POST_PROCEDURE_LIST,
        onSuccess: (dynamic response, int statusCode) {
      print("Success");
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: postProcedureReqModel.toJson());
  }
}
