import { PassportStrategy } from "@nestjs/passport";
import { Strategy, VerifyCallback } from "passport-google-oauth20";
import { Injectable } from "@nestjs/common";
import { User } from "@prisma/client";

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy) {
	constructor() {
		super({
			clientID: process.env.GOOGLE_CLIENT_ID,
			clientSecret: process.env.GOOGLE_SECRET,
			callbackURL: process.env.GOOGLE_CALLBACK_URL,
			scope: ["email", "profile"],
		});
	}

	async validate(
		_accessToken: string,
		_refreshToken: string,
		profile: any,
		done: VerifyCallback,
	): Promise<any> {
		const user = {
			email: profile.emails[0].value,
			username: profile.displayName,
			password: null,
			googleID: profile.id,
			// firstName: name.givenName,
			// lastName: name.familyName,
			// picture: photos[0].value,
		};
		done(null, user);
		return user;
	}
}
