import { registerAs } from '@nestjs/config';

export interface JwtConfig {
  secret: string;
  expiresIn: string;
  refreshSecret: string;
  refreshExpiresIn: string;
  apiKeyHeader: string;
  apiKeyValue: string;
}

export default registerAs('jwt', (): JwtConfig => {
  const secret = process.env.JWT_SECRET || 'your-super-secret-jwt-key-change-this-in-production';
  const refreshSecret =
    process.env.JWT_REFRESH_SECRET || 'your-refresh-secret-key-change-this-in-production';

  if (
    secret === 'your-super-secret-jwt-key-change-this-in-production' ||
    refreshSecret === 'your-refresh-secret-key-change-this-in-production'
  ) {
    console.warn('Warning: JWT secrets are using default values. Change these in production!');
  }

  return {
    secret,
    expiresIn: process.env.JWT_EXPIRATION || '7d',
    refreshSecret,
    refreshExpiresIn: process.env.JWT_REFRESH_EXPIRATION || '30d',
    apiKeyHeader: process.env.API_KEY_HEADER || 'X-API-Key',
    apiKeyValue: process.env.API_KEY_VALUE || 'your-api-key-change-this-in-production',
  };
});
