part of 'profit_sharing_detail_loader_bloc.dart';

@freezed
class ProfitSharingDetailLoaderState with _$ProfitSharingDetailLoaderState {
  const ProfitSharingDetailLoaderState._();

  const factory ProfitSharingDetailLoaderState({
    required ProfitSharingDetail detail,
    required Option<AnalyticFailure> failureOption,
    @Default(false) bool isFetching,
    @Default('') String parentCategoryId,
    @Default('') String expandedCategoryId,
    required DateTime dateFrom,
    required DateTime dateTo,
  }) = _ProfitSharingDetailLoaderState;

  factory ProfitSharingDetailLoaderState.initial() {
    final now = DateTime.now();
    return ProfitSharingDetailLoaderState(
      detail: ProfitSharingDetail.empty(),
      failureOption: none(),
      dateFrom: DateTime(now.year, now.month, 1),
      dateTo: DateTime(now.year, now.month + 1, 0),
    );
  }

  bool isExpanded(String categoryId) => expandedCategoryId == categoryId;
}
