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

enum CertificatesStatus { initial, loading, success, failure }

class CertificatesState extends Equatable {
  final CertificatesStatus status;
  final List<StaffDocument> certificates;
  final String? errorMessage;

  const CertificatesState({
    this.status = CertificatesStatus.initial,
    List<StaffDocument>? certificates,
    this.errorMessage,
  }) : certificates = certificates ?? const <StaffDocument>[];

  CertificatesState copyWith({
    CertificatesStatus? status,
    List<StaffDocument>? certificates,
    String? errorMessage,
  }) {
    return CertificatesState(
      status: status ?? this.status,
      certificates: certificates ?? this.certificates,
      errorMessage: errorMessage ?? this.errorMessage,
    );
  }

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

  /// The number of verified certificates.
  int get completedCount => certificates
      .where((doc) => doc.status == DocumentStatus.verified)
      .length;

  /// The total number of certificates.
  int get totalCount => certificates.length;
}
