import 'package:equatable/equatable.dart';
import 'relationship_type.dart';

/// Represents an emergency contact for a user.
///
/// Critical for staff safety during shifts.
class EmergencyContact extends Equatable {

  const EmergencyContact({
    required this.id,
    required this.name,
    required this.relationship,
    required this.phone,
  });

  /// Unique identifier.
  final String id;

  /// Full name of the contact.
  final String name;

  /// Relationship to the user (e.g. "Spouse", "Parent").
  final RelationshipType relationship;

  /// Phone number.
  final String phone;

  @override
  List<Object?> get props => <Object?>[id, name, relationship, phone];

  /// Returns a copy of this [EmergencyContact] with the given fields replaced.
  EmergencyContact copyWith({
    String? id,
    String? name,
    String? phone,
    RelationshipType? relationship,
  }) {
    return EmergencyContact(
      id: id ?? this.id,
      name: name ?? this.name,
      phone: phone ?? this.phone,
      relationship: relationship ?? this.relationship,
    );
  }

  /// Returns an empty [EmergencyContact].
  static EmergencyContact empty() {
    return const EmergencyContact(
      id: '',
      name: '',
      phone: '',
      relationship: RelationshipType.family,
    );
  }

  /// Converts a string value to a [RelationshipType].
  static RelationshipType stringToRelationshipType(String? value) {
    if (value != null) {
      final String strVal = value.toUpperCase();
      switch (strVal) {
        case 'FAMILY':
          return RelationshipType.family;
        case 'SPOUSE':
          return RelationshipType.spouse;
        case 'FRIEND':
          return RelationshipType.friend;
        case 'OTHER':
          return RelationshipType.other;
        default:
          return RelationshipType.other;
      }
    }
    return RelationshipType.other;
  }
}
