// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../../application_management.dart';

/// Priority groups exposed by the Backlog board filter UI.
enum BacklogBoardPriorityFilter {
  /// High and very high priority tasks.
  high,

  /// Medium priority tasks.
  medium,

  /// Low and very low priority tasks.
  low,
}

/// Duration buckets exposed by the Backlog board filter UI.
enum BacklogBoardDurationFilter {
  /// Tasks estimated at thirty minutes or less.
  zeroToThirty,

  /// Tasks estimated above thirty minutes and up to sixty minutes.
  thirtyToSixty,

  /// Tasks estimated above sixty minutes and up to one hundred twenty minutes.
  sixtyToOneTwenty,

  /// Tasks estimated above one hundred twenty minutes.
  overOneTwenty,
}

/// Board-specific filters that do not belong to the legacy list filter enum.
class BacklogBoardFilterSelection {
  /// Creates a board filter selection from user-facing filter groups.
  BacklogBoardFilterSelection({
    Iterable<BacklogBoardPriorityFilter> priorityGroups =
        const <BacklogBoardPriorityFilter>[],
    Iterable<String> projectIds = const <String>[],
    Iterable<BacklogBoardDurationFilter> durationBuckets =
        const <BacklogBoardDurationFilter>[],
    Iterable<BacklogBoardBucket> buckets = const <BacklogBoardBucket>[],
    this.missingDurationOnly = false,
  })  : priorityGroups = Set<BacklogBoardPriorityFilter>.unmodifiable(
          priorityGroups,
        ),
        projectIds = Set<String>.unmodifiable(projectIds),
        durationBuckets = Set<BacklogBoardDurationFilter>.unmodifiable(
          durationBuckets,
        ),
        buckets = Set<BacklogBoardBucket>.unmodifiable(buckets);

  /// Creates an empty board filter selection.
  const BacklogBoardFilterSelection.empty()
      : priorityGroups = const <BacklogBoardPriorityFilter>{},
        projectIds = const <String>{},
        durationBuckets = const <BacklogBoardDurationFilter>{},
        buckets = const <BacklogBoardBucket>{},
        missingDurationOnly = false;

  /// Selected priority groups.
  final Set<BacklogBoardPriorityFilter> priorityGroups;

  /// Selected project ids.
  final Set<String> projectIds;

  /// Selected duration buckets.
  final Set<BacklogBoardDurationFilter> durationBuckets;

  /// Selected board buckets.
  final Set<BacklogBoardBucket> buckets;

  /// Whether only tasks without a duration estimate should be returned.
  final bool missingDurationOnly;

  /// Whether this selection contains no active board filters.
  bool get isEmpty {
    return priorityGroups.isEmpty &&
        projectIds.isEmpty &&
        durationBuckets.isEmpty &&
        buckets.isEmpty &&
        !missingDurationOnly;
  }

  /// Number of active filter groups.
  int get activeFilterCount {
    return priorityGroups.length +
        projectIds.length +
        durationBuckets.length +
        buckets.length +
        (missingDurationOnly ? 1 : 0);
  }
}
