#!/usr/bin/env node
/**
 * 🧬 DSS CLI - Design System Server Organism Controller
 *
 * A portable companion for UI developers - think of it as the organism's
 * command-line nervous system. Through these commands, you can:
 *
 * - 🧬 Awaken a new organism (init)
 * - 💚 Check the organism's vital signs (status)
 * - 🩸 Direct the sensory organs to perceive Figma (extract)
 * - 🔄 Circulate extracted nutrients (sync)
 * - ⚙️ Adjust the organism's behavior (config)
 * - 🧠 Birth a conscious instance (start)
 *
 * Framework: DSS Organism Framework
 */

import { Command } from 'commander';
import chalk from 'chalk';
import { initCommand } from './commands/init.js';
import { startCommand } from './commands/start.js';
import { syncCommand } from './commands/sync.js';
import { extractCommand } from './commands/extract.js';
import { configCommand } from './commands/config.js';
import { statusCommand } from './commands/status.js';
import { stopCommand } from './commands/stop.js';

const program = new Command();

program
  .name('dss')
  .description('🧬 Design System Server - Organism Controller for UI Developers')
  .version('0.1.0');

// Init command - setup DSS in a project
program
  .command('init')
  .description('🧬 ORGANISM GENESIS - Create a new design system organism in your project')
  .option('-f, --figma-key <key>', 'Link to Figma genetic blueprint')
  .option('-t, --figma-token <token>', 'Figma sensory organ connection token')
  .action(initCommand);

// Start command - start the DSS server
program
  .command('start')
  .description('💚 ORGANISM AWAKENING - Bring the design system organism to life')
  .option('-p, --port <port>', 'Neural pathway port', '3456')
  .option('-d, --dev', 'Live consciousness mode with hot-reload')
  .option('--no-open', 'Do not open sensory interface')
  .action(startCommand);

// Sync command - sync tokens from Figma
program
  .command('sync')
  .description('🩸 NUTRIENT CIRCULATION - Distribute extracted tokens through the codebase')
  .option('-f, --format <format>', 'Nutrient format: css, scss, json, ts', 'css')
  .option('-o, --output <path>', 'Circulation destination')
  .option('--file-key <key>', 'Figma file key (overrides config)')
  .action(syncCommand);

// Extract command - extract components or tokens
program
  .command('extract <type>')
  .description('👁️ SENSORY PERCEPTION - Direct organism eyes to perceive Figma designs')
  .option('-f, --format <format>', 'Perception output format', 'json')
  .option('-o, --output <path>', 'Memory storage location')
  .option('--file-key <key>', 'Figma file key')
  .action(extractCommand);

// Config command - manage configuration
program
  .command('config')
  .description('⚙️ ENDOCRINE ADJUSTMENT - Configure organism behavior and preferences')
  .option('--set <key=value>', 'Set organism hormone value')
  .option('--get <key>', 'Read organism hormone value')
  .option('--list', 'View all hormones')
  .action(configCommand);

// Stop command - stop the server
program
  .command('stop')
  .description('😴 ORGANISM REST - Put the design system organism into sleep mode')
  .action(stopCommand);

// Status command - check DSS status
program
  .command('status')
  .description('🏥 VITAL SIGNS CHECK - Monitor organism health and configuration')
  .action(statusCommand);

// Parse arguments
program.parse();

// Show help if no command provided
if (!process.argv.slice(2).length) {
  console.log(chalk.blue(`
  ╔═══════════════════════════════════════════════════════════════╗
  ║  ${chalk.bold('DSS')} - Design System Server                                  ║
  ║  UI Developer Companion                                       ║
  ╚═══════════════════════════════════════════════════════════════╝
  `));
  program.outputHelp();
}
