import 'dart:convert';
import 'package:aves/model/entry/entry.dart';
import 'package:aves/model/filters/filters.dart';
import 'package:aves/model/filters/path.dart';

class DirectoryFilter extends CollectionFilter {
  final String directory;

  const DirectoryFilter(this.directory, {super.reversed = false});

  @override
  String get category => PathFilter.type;

  @override
  bool get exclusiveProp => false;

  @override
  String get key => directory;

  @override
  EntryPredicate get positiveTest => (AvesEntry entry) {
    final p = entry.path ?? '';
    return p.startsWith(directory);
  };

  @override
  String get universalLabel => directory;

  @override
  Map<String, dynamic> toMap() => {
        'type': category,
        'directory': directory,
        'reversed': reversed,
      };

  @override
  String toJson() => jsonEncode(toMap());

  @override
  List<Object?> get props => [category, directory, reversed];
}
