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

enum DocumentsStatus { initial, loading, success, failure }

class DocumentsState extends Equatable {
  final DocumentsStatus status;
  final List<StaffDocument> documents;
  final String? errorMessage;

  const DocumentsState({
    this.status = DocumentsStatus.initial,
    List<StaffDocument>? documents,
    this.errorMessage,
  }) : documents = documents ?? const <StaffDocument>[];

  DocumentsState copyWith({
    DocumentsStatus? status,
    List<StaffDocument>? documents,
    String? errorMessage,
  }) {
    return DocumentsState(
      status: status ?? this.status,
      documents: documents ?? this.documents,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }

  int get completedCount =>
      documents.where((StaffDocument d) => d.status == DocumentStatus.verified).length;

  int get totalCount => documents.length;

  double get progress =>
      totalCount > 0 ? completedCount / totalCount : 0.0;

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