// lib/models/user.dart

class User {
  final int? id;
  final String? email;
  final String firstname;
  final String lastname;
  final DateTime? dateOfBirth;
  late final bool female;
  final bool isActive;

  User({
    this.id,
    this.email,
    required this.firstname,
    required this.lastname,
    this.dateOfBirth,
    required this.female,
    required this.isActive,
  });

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id'],
      email: json['email'],
      firstname: json['firstname'] ?? 'Unknown',
      lastname: json['lastname'] ?? 'Unknown',
      dateOfBirth: json['date_of_birth'] != null
          ? DateTime.tryParse(json['date_of_birth'])
          : null,
      female: json['female'] ?? false,
      isActive: json['is_active'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'email': email,
      'firstname': firstname,
      'lastname': lastname,
      'date_of_birth': dateOfBirth?.toIso8601String(),
      'female': female,
      'is_active': isActive,
    };
  }
}