feat: implement emergency contact management with Firebase integration and relationship type handling
This commit is contained in:
@@ -52,6 +52,7 @@ export 'src/entities/financial/staff_payment.dart';
|
||||
// Profile
|
||||
export 'src/entities/profile/staff_document.dart';
|
||||
export 'src/entities/profile/attire_item.dart';
|
||||
export 'src/entities/profile/relationship_type.dart';
|
||||
|
||||
// Ratings & Penalties
|
||||
export 'src/entities/ratings/staff_rating.dart';
|
||||
@@ -77,3 +78,6 @@ export 'src/entities/home/reorder_item.dart';
|
||||
// Availability
|
||||
export 'src/entities/availability/availability_slot.dart';
|
||||
export 'src/entities/availability/day_availability.dart';
|
||||
|
||||
// Adapters
|
||||
export 'src/adapters/profile/emergency_contact_adapter.dart';
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import '../../entities/profile/emergency_contact.dart';
|
||||
|
||||
/// Adapter for [EmergencyContact] to map data layer values to domain entity.
|
||||
class EmergencyContactAdapter {
|
||||
/// Maps primitive values to [EmergencyContact].
|
||||
static EmergencyContact fromPrimitives({
|
||||
required String id,
|
||||
required String name,
|
||||
required String phone,
|
||||
String? relationship,
|
||||
}) {
|
||||
return EmergencyContact(
|
||||
id: id,
|
||||
name: name,
|
||||
phone: phone,
|
||||
relationship: EmergencyContact.stringToRelationshipType(relationship),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'relationship_type.dart';
|
||||
|
||||
/// Represents an emergency contact for a user.
|
||||
///
|
||||
@@ -6,19 +7,69 @@ import 'package:equatable/equatable.dart';
|
||||
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 String relationship;
|
||||
final RelationshipType relationship;
|
||||
|
||||
/// Phone number.
|
||||
final String phone;
|
||||
|
||||
@override
|
||||
List<Object?> get props => <Object?>[name, relationship, phone];
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
enum RelationshipType {
|
||||
family,
|
||||
spouse,
|
||||
friend,
|
||||
other,
|
||||
}
|
||||
Reference in New Issue
Block a user