import 'package:mitra_corporate/model/search_patient_model.dart';

import '../app/constant.dart';
import '../model/registration_model.dart';
import 'base_repository.dart';

class PatientRepository extends BaseRepository {
  PatientRepository({required super.dio});

  Future<SearchPatientModel> search(
      {required String token,
      required String page,
      required String keyword,
      required String rpp,
      required String companyID}) async {
    final param = {
      "token": token,
      "keyword": keyword,
      "page": page,
      "rpp": rpp,
      "company_id": companyID
    };
    // print(param);
    final service = "${Constant.baseUrl}patient/search";
    final resp = await post(param: param, service: service);
    SearchPatientModel data;
    // print(resp);
    if (resp['status'] == 'OK') {
      data = SearchPatientModel.fromJson(resp['data']);
    } else {
      data = SearchPatientModel();
    }

    return data;
  }

  Future<String> editPatient({required RegistrationModel prm}) async {
    final url = "${Constant.baseUrl}Patient/editpatient";
    final resp = await post(param: prm.toJson(), service: url);
    String msg;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      msg = resp['data'];
    } else {
      msg = "";
    }

    return msg;
  }

  Future<String> deletePatient(
      {required String patient_id, required String token}) async {
    final prm = {"patient_id": patient_id, "token": token};
    final url = "${Constant.baseUrl}Patient/deletePatient";
    final resp = await post(param: prm, service: url);
    String msg;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      msg = resp['data'];
    } else {
      msg = "";
    }

    return msg;
  }
}
