import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

class GoogleSignInProvider extends ChangeNotifier{
  final googleSignIn = GoogleSignIn();

  GoogleSignInAccount? _user;
  GoogleSignInAuthentication? googleAuth;

  GoogleSignInAccount get user => _user!;

  Future googleLogin() async{
    final googleUser = await googleSignIn.signIn();
    if(googleUser==null) return;
    _user = googleUser;

    googleAuth = await googleUser.authentication;

    final credential = GoogleAuthProvider.credential(
      accessToken: googleAuth!.accessToken,
      idToken: googleAuth!.idToken
    );
    print('user login\nusername:${googleUser.displayName}\nemail:${googleUser.email}\nid:${googleAuth!.idToken}');
    print(googleAuth!.accessToken!.length);

    notifyListeners();
  }

  Future logout() async{
    await googleSignIn.disconnect();
  }
}