import 'package:flutter_test/flutter_test.dart';
import 'package:iop_client/iop_wire/parser_map.dart';
import 'package:iop_client/gen/proto/iop/control.pb.dart';

void main() {
  test(
    'Parser map should contain ClientHelloRequest and ClientHelloResponse',
    () {
      expect(clientParserMap.containsKey('iop.ClientHelloRequest'), isTrue);
      expect(clientParserMap.containsKey('iop.ClientHelloResponse'), isTrue);
      expect(clientParserMap.containsKey('ClientHelloRequest'), isTrue);
      expect(clientParserMap.containsKey('ClientHelloResponse'), isTrue);

      // Verify parser works
      final req = ClientHelloRequest()
        ..clientId = 'test-client'
        ..clientVersion = '1.0.0';
      final reqBytes = req.writeToBuffer();

      final parserReq = clientParserMap['ClientHelloRequest'];
      expect(parserReq, isNotNull);
      final parsedReq = parserReq!(reqBytes) as ClientHelloRequest;
      expect(parsedReq.clientId, equals('test-client'));
      expect(parsedReq.clientVersion, equals('1.0.0'));

      final res = ClientHelloResponse()
        ..ready = true
        ..protocol = 'proto'
        ..message = 'welcome';
      final resBytes = res.writeToBuffer();

      final parserRes = clientParserMap['ClientHelloResponse'];
      expect(parserRes, isNotNull);
      final parsedRes = parserRes!(resBytes) as ClientHelloResponse;
      expect(parsedRes.ready, isTrue);
      expect(parsedRes.protocol, equals('proto'));
      expect(parsedRes.message, equals('welcome'));
    },
  );
}
