/**
 * DSS Stop Command
 *
 * Stop the DSS server.
 */

import chalk from 'chalk';
import { getProjectRoot } from '../lib/config.js';
import { isServerRunning, stopServer, getServerPid } from '../lib/server.js';

export async function stopCommand(): Promise<void> {
  const cwd = getProjectRoot();

  if (!isServerRunning(cwd)) {
    console.log(chalk.yellow('  DSS is not running'));
    return;
  }

  const pid = getServerPid(cwd);
  console.log(chalk.dim(`  Stopping DSS (PID: ${pid})...`));

  await stopServer(cwd);

  console.log(chalk.green('  DSS stopped'));
}
