import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { SeedConfig } from '../shared/types';

export async function loadSeedConfig(): Promise<SeedConfig | null> {
  // For development, we look in the home directory
  const configPath = path.join(os.homedir(), 'seed.json');

  try {
    if (!fs.existsSync(configPath)) {
      console.log(`Seed config not found at: ${configPath}`);
      return null;
    }

    const data = fs.readFileSync(configPath, 'utf-8');
    const config = JSON.parse(data) as SeedConfig;

    // Basic validation
    if (!config.event_device_id) {
      console.error('Invalid seed config: missing event_device_id');
      return null;
    }

    return config;
  } catch (error) {
    console.error('Error loading seed config:', error);
    return null;
  }
}
