import 'package:fis_jsonrpc/rpc.dart';
import 'package:vnoteapp/managers/interfaces/patient.dart';
import 'package:vnoteapp/rpc.dart';
import 'package:fis_common/logger/logger.dart';
import 'package:vnoteapp/store/store.dart';

class PatientManager implements IPatientManager {
  @override
  Future<String?> create(CreatePatientRequest request) async {
    try {
      request.token = Store.user.token;
      final result = await rpc.patient.createPatientAsync(request);
      return result;
    } catch (e) {
      logger.e("PatientManager create patient error.", e);
      return null;
    }
  }

  @override
  Future<PatientDTO?> getDetail(String code) async {
    try {
      final result = await rpc.patient.getPatientDetailAsync(
        GetPatientRequest(code: code, token: Store.user.token),
      );
      return result;
    } catch (e) {
      logger.e("PatientManager query patient detail error.", e);
      return null;
    }
  }

  @override
  Future<PageCollection<PatientDTO>?> getPagedList(
      PatientPageRequest request) async {
    try {
      request.token = Store.user.token;
      final result = await rpc.patient.getPatientPageAsync(request);
      return result;
    } catch (e) {
      logger.e("PatientManager query patient paged list error.", e);
      return null;
    }
  }
}
