import 'package:flutter_test/flutter_test.dart';
import 'package:kell_web/navigation/navigation_target.dart';

void main() {
  group('NavigationTarget', () {
    test('creates with route and empty arguments by default', () {
      const target = NavigationTarget(route: '/inventory');
      expect(target.route, '/inventory');
      expect(target.arguments, isEmpty);
    });

    test('creates with route and arguments', () {
      const target = NavigationTarget(route: '/products', arguments: {'selectedSku': 'ABC-123'});
      expect(target.route, '/products');
      expect(target.arguments, {'selectedSku': 'ABC-123'});
    });

    test('convenience getters return correct values', () {
      const target = NavigationTarget(
        route: '/inventory',
        arguments: {
          'selectedSku': 'SKU-001',
          'selectedId': 'ID-001',
          'filter': 'lowStock',
          'category': 'Product Compliance',
          'query': 'coaster',
        },
      );
      expect(target.selectedSku, 'SKU-001');
      expect(target.selectedId, 'ID-001');
      expect(target.filter, 'lowStock');
      expect(target.category, 'Product Compliance');
      expect(target.query, 'coaster');
    });

    test('convenience getters return null when key is absent', () {
      const target = NavigationTarget(route: '/orders');
      expect(target.selectedSku, isNull);
      expect(target.selectedId, isNull);
      expect(target.filter, isNull);
      expect(target.category, isNull);
      expect(target.query, isNull);
    });

    test('equality works for same route and arguments', () {
      const a = NavigationTarget(route: '/products', arguments: {'selectedSku': 'X'});
      const b = NavigationTarget(route: '/products', arguments: {'selectedSku': 'X'});
      expect(a, equals(b));
      expect(a.hashCode, equals(b.hashCode));
    });

    test('inequality for different routes', () {
      const a = NavigationTarget(route: '/products');
      const b = NavigationTarget(route: '/orders');
      expect(a, isNot(equals(b)));
    });

    test('inequality for different arguments', () {
      const a = NavigationTarget(route: '/products', arguments: {'selectedSku': 'X'});
      const b = NavigationTarget(route: '/products', arguments: {'selectedSku': 'Y'});
      expect(a, isNot(equals(b)));
    });

    test('toString includes route and arguments', () {
      const target = NavigationTarget(route: '/inventory', arguments: {'filter': 'lowStock'});
      expect(target.toString(), contains('/inventory'));
      expect(target.toString(), contains('lowStock'));
    });

    test('query argument round-trips through convenience getter', () {
      const target = NavigationTarget(route: '/inventory', arguments: {'query': 'bowl cozy'});
      expect(target.query, 'bowl cozy');
    });
  });
}
