import { DattoRMMClient } from './datto-rmm-client';
import { DattoRMMConfig } from '@/lib/types/datto-rmm';

let clientInstance: DattoRMMClient | null = null;

export function getDattoRMMClient(): DattoRMMClient {
  if (!clientInstance) {
    const config: DattoRMMConfig = {
      apiUrl: process.env.DATTO_RMM_API_URL || '',
      apiKey: process.env.DATTO_RMM_API_KEY || '',
      apiSecret: process.env.DATTO_RMM_API_SECRET || '',
    };

    // Validate configuration
    if (!config.apiUrl || !config.apiKey || !config.apiSecret) {
      throw new Error(
        'Missing Datto RMM API configuration. Please check your environment variables.'
      );
    }

    clientInstance = new DattoRMMClient(config);
  }

  return clientInstance;
}
