namespace App\Services;

use App\Models\User;
use Laravel\Socialite\Facades\Socialite;
use Illuminate\Support\Facades\Auth;

class GoogleService
{
    public function handleGoogleLogin()
    {
        // Fetch user details from Google
        return Socialite::driver('google')->stateless()->user();
    }

    public function findOrCreateUser($googleUser)
    {
        // Find or create the user
        return User::firstOrCreate(
            ['email' => $googleUser->getEmail()],
            [
                'name' => $googleUser->getName(),
                'google_id' => $googleUser->getId(),
                'password' => bcrypt('default-password') // Optional
            ]
        );
    }

    public function loginUser($user)
    {
        Auth::login($user);
    }
}
  