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

enum EmergencyContactStatus { initial, loading, loaded, saving, saved, failure }

class EmergencyContactState extends Equatable {
  final EmergencyContactStatus status;
  final List<EmergencyContact> contacts;
  final String? errorMessage;

  const EmergencyContactState({
    this.status = EmergencyContactStatus.initial,
    this.contacts = const [],
    this.errorMessage,
  });

  EmergencyContactState copyWith({
    EmergencyContactStatus? status,
    List<EmergencyContact>? contacts,
    String? errorMessage,
  }) {
    return EmergencyContactState(
      status: status ?? this.status,
      contacts: contacts ?? this.contacts,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }

  bool get isValid {
    if (contacts.isEmpty) return false;
    // Check if at least one contact is valid (or all?) 
    // Usually all added contacts should be valid.
    return contacts.every((c) => c.name.isNotEmpty && c.phone.isNotEmpty);
  }

  @override
  List<Object?> get props => [status, contacts, errorMessage];
}
