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

/// Enum representing the various states of the authentication process.
enum ClientAuthStatus {
  /// Initial state before any action is taken.
  initial,

  /// An authentication operation is in progress.
  loading,

  /// The user has successfully authenticated.
  authenticated,

  /// The user has successfully signed out.
  signedOut,

  /// An error occurred during authentication.
  error,
}

/// Represents the state of the client authentication flow.
class ClientAuthState extends Equatable {

  const ClientAuthState({
    this.status = ClientAuthStatus.initial,
    this.user,
    this.errorMessage,
  });
  /// Current status of the authentication process.
  final ClientAuthStatus status;

  /// The authenticated user (if status is [ClientAuthStatus.authenticated]).
  final User? user;

  /// Optional error message when status is [ClientAuthStatus.error].
  final String? errorMessage;

  /// Creates a copy of this state with the given fields replaced by the new values.
  ClientAuthState copyWith({
    ClientAuthStatus? status,
    User? user,
    String? errorMessage,
  }) {
    return ClientAuthState(
      status: status ?? this.status,
      user: user ?? this.user,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }

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