// backend/src/services/AuthService.ts
import * as dotenv from 'dotenv';
import * as path from 'path';

dotenv.config({ path: path.resolve(__dirname, '../../.env') });

export class AuthService {
  private static passphrase: string | undefined = process.env.AUTH_PASSPHRASE;

  public static getPassphrase(): string | undefined {
    return AuthService.passphrase;
  }

  public static isAuthEnabled(): boolean {
    return !!AuthService.passphrase && AuthService.passphrase.trim() !== '';
  }

  public static validatePassphrase(inputPassphrase: string): boolean {
    console.log('AuthService: AUTH_PASSPHRASE from process.env:', process.env.AUTH_PASSPHRASE);
    console.log('AuthService: Stored passphrase:', AuthService.passphrase);
    if (!AuthService.isAuthEnabled()) {
      return true; // If auth is not enabled, any passphrase is "valid"
    }
    return inputPassphrase === AuthService.passphrase;
  }
}
