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 refreshSessionGrpcProvider = Provider<RefreshSessionGrpcRepository>((
  ref,
) {
  return RefreshSessionGrpcRepository(
    ref.watch(refreshSessionServiceClientProvider),
  );
});

class RefreshSessionGrpcRepository {
  final RefreshSessionServiceClient _client;
  RefreshSessionGrpcRepository(this._client);

  ResponseFuture<RefreshSessionResponse> refreshSession(String refreshToken) {
    try {
      final response = _client.refreshSession(
        RefreshSessionRequest(refreshToken: refreshToken),
      );
      return response;
    } catch (error) {
      rethrow;
    }
  }
}
