import 'dart:convert';

class PrimaryInformation {
  PrimaryInformation({
    required this.id,
    required this.lastName,
    required this.firstName,
    required this.middleName,
    required this.nameExtension,
    required this.sex,
    required this.birthdate,
    required this.civilStatus,
    required this.bloodType,
    required this.heightM,
    required this.weightKg,
    required this.photoPath,
    required this.esigPath,
    required this.maidenName,
    required this.deceased,
    required this.gender,
    required this.uuidQrcode,
    required this.titlePrefix,
    required this.titleSuffix,
    required this.showTitleId,
  });

  int? id;
  String? lastName;
  String? firstName;
  String? middleName;
  String? nameExtension;
  String? sex;
  DateTime? birthdate;
  String? civilStatus;
  String? bloodType;
  double? heightM;
  double? weightKg;
  String? photoPath;
  String? esigPath;
  String? maidenName;
  bool? deceased;
  String? gender;
  String? uuidQrcode;
  String? titlePrefix;
  String? titleSuffix;
  bool? showTitleId;

  factory PrimaryInformation.fromJson(Map<String, dynamic> json) =>
      PrimaryInformation(
        id: json["id"],
        lastName: json["last_name"],
        firstName: json["first_name"],
        middleName: json["middle_name"],
        nameExtension: json["name_extension"],
        sex: json["sex"],
        birthdate: json['birthdate']==null?null:DateTime.parse(json["birthdate"]),
        civilStatus: json["civil_status"],
        bloodType: json["blood_type"],
        heightM: json["height_m"]?.toDouble(),
        weightKg: json["weight_kg"],
        photoPath: json["photo_path"],
        esigPath: json["esig_path"],
        maidenName: json["maiden_name"],
        deceased: json["deceased"],
        gender: json["gender"],
        uuidQrcode: json["uuid_qrcode"],
        titlePrefix: json["title_prefix"],
        titleSuffix: json["title_suffix"],
        showTitleId: json["show_title_id"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "last_name": lastName,
        "first_name": firstName,
        "middle_name": middleName,
        "name_extension": nameExtension,
        "sex": sex,
        "birthdate":
            "${birthdate!.year.toString().padLeft(4, '0')}-${birthdate!.month.toString().padLeft(2, '0')}-${birthdate!.day.toString().padLeft(2, '0')}",
        "civil_status": civilStatus,
        "blood_type": bloodType,
        "height_m": heightM,
        "weight_kg": weightKg,
        "photo_path": photoPath,
        "esig_path": esigPath,
        "maiden_name": maidenName,
        "deceased": deceased,
        "gender": gender,
        "uuid_qrcode": uuidQrcode,
        "title_prefix": titlePrefix,
        "title_suffix": titleSuffix,
        "show_title_id": showTitleId,
      };
}
