import 'package:fis_jsonrpc/services/patient.m.dart';
import 'package:fis_jsonrpc/services/patientExtension.m.dart';

abstract class PatientDtoConverter {
  /// 根据新建请求创建DTO
  static PatientDTO create2Dto(CreatePatientRequest request) {
    final dto = PatientDTO();
    dto.code = request.code;
    dto.patientName = request.patientName;
    dto.phone = request.phone;
    dto.cardNo = request.cardNo;
    dto.nationality = request.nationality;
    dto.birthday = request.birthday;
    dto.crowdLabels = request.crowdLabels;
    dto.cardType = request.cardType;
    dto.patientGender = request.patientGender;
    dto.patientAddress = request.patientAddress;
    dto.permanentResidenceAddress = request.permanentResidenceAddress;
    dto.teamRegionCode = request.teamRegionCode;
    dto.contractedDoctor = request.contractedDoctor;
    return dto;
  }

  /// 根据DTO创建新建请求
  static CreatePatientRequest dto2Create(PatientDTO dto) {
    final dtoJson = dto.toJson();
    final request = CreatePatientRequest.fromJson(dtoJson);
    return request;
  }

  /// 同步更新到DTO
  static void syncUpdate2Dto(PatientDTO dto, UpdatePatientRequest request) {
    dto.code = request.code;
    dto.patientName = request.patientName;
    dto.phone = request.phone;
    dto.cardNo = request.cardNo;
    dto.nationality = request.nationality;
    dto.birthday = request.birthday;
    dto.crowdLabels = request.crowdLabels;
    if (request.cardType != null) {
      dto.cardType = request.cardType!;
    }
    if (request.patientGender != null) {
      dto.patientGender = request.patientGender!;
    }
    dto.patientAddress = request.patientAddress;
    dto.permanentResidenceAddress = request.permanentResidenceAddress;
    dto.teamRegionCode = request.teamRegionCode;
    dto.contractedDoctor = request.contractedDoctor;
  }

  /// 根据DTO创建更新请求
  static UpdatePatientRequest dto2Update(PatientDTO dto) {
    final dtoJson = dto.toJson();
    final request = UpdatePatientRequest.fromJson(dtoJson);
    return request;
  }
}

abstract class PatientExtDtoConverter {
  /// 根据新建请求创建DTO
  static PatientExtensionDTO create2Dto(CreatePatientExtensionRequest request) {
    final dto = PatientExtensionDTO();
    // dto.code = request.code;
    // dto.patientName = request.patientName;
    // dto.phone = request.phone;
    // dto.cardNo = request.cardNo;
    // dto.nationality = request.nationality;
    // dto.birthday = request.birthday;
    // dto.crowdLabels = request.crowdLabels;
    // dto.cardType = request.cardType;
    // dto.patientGender = request.patientGender;
    // dto.patientAddress = request.patientAddress;
    // dto.permanentResidenceAddress = request.permanentResidenceAddress;
    // dto.teamRegionCode = request.teamRegionCode;
    // dto.contractedDoctor = request.contractedDoctor;
    return dto;
  }

  /// 根据DTO创建新建请求
  static CreatePatientExtensionRequest dto2Create(PatientExtensionDTO dto) {
    final dtoJson = dto.toJson();
    final request = CreatePatientExtensionRequest.fromJson(dtoJson);
    return request;
  }

  /// 同步更新到DTO
  static void syncUpdate2Dto(
      PatientExtensionDTO dto, UpdatePatientExtensionRequest request) {}

  /// 根据DTO创建更新请求
  static UpdatePatientExtensionRequest dto2Update(PatientExtensionDTO dto) {
    final dtoJson = dto.toJson();
    final request = UpdatePatientExtensionRequest.fromJson(dtoJson);
    return request;
  }
}
