package com.swago.login

import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.swago.baseswago.util.AppContext

/**
 *@date 2021/11/8 15:04
 *description:
 */
object GoogleLogin {

    private var client:GoogleSignInClient? = null
    const val requestCode = 1234

    fun init(activity: LoginActivity){
        val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(AppContext.getContext().resources.getString(R.string.google_id))
            .requestServerAuthCode(AppContext.getContext().resources.getString(R.string.google_id))
            .build()
        client = GoogleSignIn.getClient(activity, googleSignInOptions)
    }


    fun login(activity: LoginActivity){
        client?.let {
            activity.startActivityForResult(it.signInIntent, requestCode)
        }
    }

}