// Same content as integration_test/simple_test.dart, but runnable via
// `flutter test` (flutter_tester, no display required).
//
// Reasoning: the PoC exit criterion is "Flutter can call Rust and receive
// event stream data". flutter_rust_bridge v2 uses dart:ffi on desktop,
// which works inside flutter_tester. A full integration_test driver run
// is not required to evidence the criterion.

import 'package:flutter_rust_bridge_hello/src/rust/api/simple.dart';
import 'package:flutter_rust_bridge_hello/src/rust/frb_generated.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  setUpAll(() async => await RustLib.init());

  group('Chanora FRB hello PoC', () {
    test('greet() returns typed result for valid input', () {
      final r = greet(name: 'Chanora');
      expect(r.message, contains('Hello, Chanora!'));
      expect(r.elapsedMicros.toInt(), greaterThanOrEqualTo(0));
    });

    test('greet() surfaces typed error for empty input', () {
      expect(() => greet(name: '   '), throwsA(isA<GreetError>()));
    });

    test('counterStream() delivers the expected event sequence', () async {
      const count = 4;
      final events = <CounterTick>[];
      await for (final tick in counterStream(count: count, intervalMs: 50)) {
        events.add(tick);
      }
      expect(events, hasLength(count));
      for (var i = 0; i < count; i++) {
        expect(events[i].seq.toInt(), i);
        expect(events[i].note, 'tick $i/$count');
      }
    });
  });
}
