import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_dart_proto/accounts/v1/accounts_v1.pbgrpc.dart';
import 'package:softplayer_web/core/grpc/grpc_client.dart';

final publicAccountsGrpcProvider = Provider<PublicAccountsGrpcRepository>((
  ref,
) {
  return PublicAccountsGrpcRepository(
    ref.watch(publicAccountsServiceClientProvider),
  );
});

class PublicAccountsGrpcRepository {
  PublicAccountsGrpcRepository(this._client);
  final PublicAccountsServiceClient _client;

  ResponseFuture<SignInResponse> signIn(SignInRequest req) {
    try {
      final response = _client.signIn(req);
      return response;
    } catch (error) {
      rethrow;
    }
  }

  ResponseFuture<SignUpResponse> signUp(SignUpRequest req) {
    try {
      final response = _client.signUp(req);
      return response;
    } catch (error) {
      rethrow;
    }
  }
}
