import { Injectable, UnauthorizedException } from '@nestjs/common'
import { AuthMethod, AuthStrategy } from '../types'
import { GoogleBookingServerAuthStrategy } from './google-booking-server.strategy'
import { JWTAuthStrategy } from './jwt.strategy'

@Injectable()
export class AuthStrategyFactory {
	constructor(
		private readonly _jwt: JWTAuthStrategy,
		private readonly _googleBookingServer: GoogleBookingServerAuthStrategy,
	) {}

	createStrategy(strategy: AuthMethod): AuthStrategy {
		switch (strategy) {
			case AuthMethod.JWT: {
				return this._jwt
			}
			case AuthMethod.GoogleBookingServer: {
				return this._googleBookingServer
			}
			default: {
				throw new UnauthorizedException(`Unknown auth strategy: ${strategy}`)
			}
		}
	}
}
