import fs from 'fs-extra';
import chalk from 'chalk';

export const createHealthAlarmNotifyConf = async (): Promise<string> => {
  const sourcePath =
    '/opt/netdata/usr/lib/netdata/conf.d/health_alarm_notify.conf';
  const targetPath = '/opt/netdata/etc/netdata/health_alarm_notify.conf';

  try {
    if (!(await fs.pathExists(sourcePath))) {
      throw new Error(`Source file not found: ${sourcePath}`);
    }

    await fs.ensureDir('/opt/netdata/etc/netdata/');

    await fs.copy(sourcePath, targetPath);

    console.log(
      chalk.green(`✅ Created health_alarm_notify.conf at ${targetPath}`),
    );

    return targetPath;
  } catch (error) {
    console.error(
      chalk.red(`❌ Failed to create health_alarm_notify.conf: ${error}`),
    );
    throw error;
  }
};
