import 'user_info.dart';
import 'vital_sign_camera_config.dart';
import 'preview_layer_gravity.dart';

extension on Gender {
  /// Convert [Gender] to integer value.
  int toInt() {
    if (this == Gender.male) {
      return 0;
    } else {
      return 1;
    }
  }
}

extension UserInfoExt on UserInfo {
  /// The map representing [UserInfo].
  Map<String, dynamic> get map {
    Map<String, dynamic> map = <String, dynamic>{};
    map['age'] = age;
    map['gender'] = gender.toInt();
    if (weight != null) {
      map['weight'] = weight;
    }
    if (height != null) {
      map['height'] = height;
    }
    if (smoker != null) {
      map['smoker'] = smoker;
    }
    if (hypertension != null) {
      map['hypertension'] = hypertension;
    }
    if (bpMedication != null) {
      map['bpMedication'] = bpMedication;
    }
    if (diabetic != null) {
      map['diabetic'] = diabetic;
    }
    if (userId != null) {
      map['userId'] = userId;
    }
    if (waistCircumference != null) {
      map['waistCircumference'] = waistCircumference;
    }
    if (appUserId != null) {
      map['appUserId'] = appUserId;
    }
    return map;
  }
}

extension PreviewLayerGravityExt on PreviewLayerGravity {
  int toInt() {
    if (this == PreviewLayerGravity.resizeAspectFill) {
      return 0;
    } else {
      return 1;
    }
  }
}

extension ServerIdExt on ServerId {
  /// Convert [ServerId] to integer value.
  int toInt() {
    switch (this) {
      case ServerId.local:
        return 0;
      case ServerId.remoteDev:
        return 1;
      case ServerId.remoteProd:
        return 2;
      case ServerId.awsDev:
        return 3;
      case ServerId.awsProd:
        return 4;
      case ServerId.awsFirebaseEnterpriseProd:
        return 5;
      case ServerId.awsEnterpriseProd:
        return 6;
      case ServerId.awsEnterpriseDev:
        return 7;
    }
  }
}

extension VitalSignCameraConfigExt on VitalSignCameraConfig {
  /// The map representing [VitalSignCameraConfig].
  Map<String, dynamic> get map {
    Map<String, dynamic> map = <String, dynamic>{};
    if (serverId != null) {
      map['serverId'] = serverId!.toInt();
    }
    if (apiKey != null) {
      map['apiKey'] = apiKey;
    }
    return map;
  }
}
