import 'dart:developer';

import 'package:grpc/grpc_web.dart';
import 'package:softplayer_dart_proto/src/test/v1/test_v1.pb.dart';
import 'package:softplayer_dart_proto/src/test/v1/test_v1.pbgrpc.dart';

class TestAuthGrpc {
  final GrpcWebClientChannel channel;
  late TestServiceClient serviceStub;
  TestAuthGrpc({required this.channel});

  void init() {
    serviceStub = TestServiceClient(channel);
  }

  Future<void> pong() async {
    final request = PongRequest();
    try {
      final response = await serviceStub.pong(request);
      log(response.toString());
    } catch (e) {
      rethrow;
    }
  }
}

class TestNoAuthGrpc {
  final GrpcWebClientChannel channel;
  late PublicTestServiceClient serviceStub;
  TestNoAuthGrpc({required this.channel});

  void init() {
    serviceStub = PublicTestServiceClient(channel);
  }

  Future<void> ping() async {
    final request = PingRequest();
    try {
      final response = await serviceStub.ping(request);
      log(response.toString());
    } catch (e) {
      rethrow;
    }
  }
}
