import { describe, expect, it } from 'bun:test';
import { TERMINAL_COMMAND_SPECS } from './terminalCommandSpecs';
import { resolveTerminalShadow } from './terminalShadow';
import { resolveTickerCommandFallback } from './tickerHistory';

describe('mappings terminal command metadata', () => {
  it('includes a dedicated /mappings add command spec', () => {
    const spec = TERMINAL_COMMAND_SPECS.find(
      (candidate) => candidate.command === '/mappings add',
    );

    expect(spec).toBeDefined();
    expect(spec?.arguments).toHaveLength(1);
    expect(spec?.arguments[0]?.consumeRest).toBe(true);
  });

  it('treats mappings add payload as a rest argument in terminal shadow', () => {
    const shadow = resolveTerminalShadow(
      '/mappings add {"targetField":"total_revenues","scope":{"ticker":"AAPL"}}',
    );

    expect(shadow?.spec.command).toBe('/mappings add');
    expect(shadow?.arguments[0]?.value).toBe(
      '{"targetField":"total_revenues","scope":{"ticker":"AAPL"}}',
    );
    expect(shadow?.hasExtraInput).toBe(false);
    expect(shadow?.readyToRun).toBe(true);
  });

  it('does not rewrite mappings add commands with ticker fallback', () => {
    expect(
      resolveTickerCommandFallback(
        '/mappings add {"targetField":"total_revenues"}',
        'NVDA',
      ),
    ).toBe('/mappings add {"targetField":"total_revenues"}');
  });
});
