import 'package:flutter_test/flutter_test.dart';

import 'package:feature_orders/feature_orders.dart';

void main() {
  late FakeOrdersRepository repository;

  setUp(() {
    repository = FakeOrdersRepository();
  });

  group('FakeOrdersRepository', () {
    test('getOrders returns six sample orders', () async {
      final orders = await repository.getOrders();
      expect(orders.length, 6);
    });

    test('getOrders returns orders with expected IDs', () async {
      final orders = await repository.getOrders();
      final ids = orders.map((o) => o.id).toList();
      expect(ids, contains('KC-1001'));
      expect(ids, contains('KC-1002'));
      expect(ids, contains('KC-1003'));
      expect(ids, contains('KC-1004'));
      expect(ids, contains('KC-1005'));
      expect(ids, contains('KC-1006'));
    });

    test('getOrders returns orders with various statuses', () async {
      final orders = await repository.getOrders();
      final statuses = orders.map((o) => o.status).toSet();
      expect(statuses, contains(OrderStatus.pending));
      expect(statuses, contains(OrderStatus.processing));
      expect(statuses, contains(OrderStatus.shipped));
      expect(statuses, contains(OrderStatus.delivered));
      expect(statuses, contains(OrderStatus.cancelled));
    });

    test('order totals are computed correctly', () async {
      final orders = await repository.getOrders();
      // KC-1001: 2 * 12.99 + 1 * 16.50 = 42.48
      final order1001 = orders.firstWhere((o) => o.id == 'KC-1001');
      expect(order1001.total, closeTo(42.48, 0.01));
    });

    test('order item count is computed correctly', () async {
      final orders = await repository.getOrders();
      // KC-1001: 2 + 1 = 3 items
      final order1001 = orders.firstWhere((o) => o.id == 'KC-1001');
      expect(order1001.itemCount, 3);
    });
  });
}
