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 with canonical full-name keys',
    () {
      // Canonical full-name keys must be present
      expect(clientParserMap.containsKey('iop.ClientHelloRequest'), isTrue);
      expect(clientParserMap.containsKey('iop.ClientHelloResponse'), isTrue);

      // Short-name keys must NOT be present (proto-socket handles alias internally)
      expect(clientParserMap.containsKey('ClientHelloRequest'), isFalse);
      expect(clientParserMap.containsKey('ClientHelloResponse'), isFalse);

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

      final parserReq = clientParserMap['iop.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['iop.ClientHelloResponse'];
      expect(parserRes, isNotNull);
      final parsedRes = parserRes!(resBytes) as ClientHelloResponse;
      expect(parsedRes.ready, isTrue);
      expect(parsedRes.protocol, equals('proto'));
      expect(parsedRes.message, equals('welcome'));
    },
  );
}
