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

/// Represents the status of personal info operations.
enum PersonalInfoStatus {
  /// Initial state.
  initial,

  /// Loading data.
  loading,

  /// Data loaded successfully.
  loaded,

  /// Saving data.
  saving,

  /// Data saved successfully.
  saved,

  /// Uploading photo.
  uploadingPhoto,

  /// An error occurred.
  error,
}

/// State for the Personal Info BLoC.
///
/// Uses the shared [Staff] entity from the domain layer.
class PersonalInfoState extends Equatable {
  /// The current status of the operation.
  final PersonalInfoStatus status;

  /// The staff profile information.
  final Staff? staff;

  /// The form values being edited.
  final Map<String, dynamic> formValues;

  /// Error message if an error occurred.
  final String? errorMessage;

  /// Creates a [PersonalInfoState].
  const PersonalInfoState({
    this.status = PersonalInfoStatus.initial,
    this.staff,
    this.formValues = const {},
    this.errorMessage,
  });

  /// Initial state.
  const PersonalInfoState.initial()
      : status = PersonalInfoStatus.initial,
        staff = null,
        formValues = const {},
        errorMessage = null;

  /// Creates a copy of this state with the given fields replaced.
  PersonalInfoState copyWith({
    PersonalInfoStatus? status,
    Staff? staff,
    Map<String, dynamic>? formValues,
    String? errorMessage,
  }) {
    return PersonalInfoState(
      status: status ?? this.status,
      staff: staff ?? this.staff,
      formValues: formValues ?? this.formValues,
      errorMessage: errorMessage,
    );
  }

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