import 'package:flutter/foundation.dart';

@immutable
final class EmergencyContactModel {
  const EmergencyContactModel({
    this.contactId,
    required this.firstName,
    required this.lastName,
    required this.phoneNumber,
  });

  const EmergencyContactModel.empty({
    this.contactId,
    this.firstName = '',
    this.lastName = '',
    this.phoneNumber = '',
  });

  factory EmergencyContactModel.fromJson(Map<String, dynamic> json) {
    return EmergencyContactModel(
      contactId: json['id'] as String?,
      firstName: json['first_name'] as String? ?? '',
      lastName: json['last_name'] as String? ?? '',
      phoneNumber: json['phone'] as String? ?? '',
    );
  }

  final String? contactId;
  final String firstName;
  final String lastName;
  final String phoneNumber;

  bool get isFilled =>
      firstName.isNotEmpty && lastName.isNotEmpty && phoneNumber.isNotEmpty;

  EmergencyContactModel copyWith({
    String? contactId,
    String? firstName,
    String? lastName,
    String? phoneNumber,
    bool? isSaved,
  }) {
    return EmergencyContactModel(
      contactId: contactId ?? this.contactId,
      firstName: firstName ?? this.firstName,
      lastName: lastName ?? this.lastName,
      phoneNumber: phoneNumber ?? this.phoneNumber,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'first_name': firstName,
      'last_name': lastName,
      'phone': phoneNumber,
    };
  }
}
