package com.pixelized.biblib.repository.googleSignIn

import android.app.Application
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.pixelized.biblib.R

class GoogleSingInRepository(application: Application) : IGoogleSingInRepository {

    override val option: GoogleSignInOptions by lazy {
        GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(application.getString(R.string.biblib_server_id))
            .requestEmail()
            .build()
    }

    override val client: GoogleSignInClient by lazy {
        GoogleSignIn.getClient(application, option)
    }

    override val account: GoogleSignInAccount? by lazy {
        GoogleSignIn.getLastSignedInAccount(application)
    }

    override val lastGoogleToken: String? by lazy {
        GoogleSignIn.getLastSignedInAccount(application)?.idToken
    }
}