import { describe, it, expect, vi } from 'vitest';

import { createElevateCommand, createModelCommand } from './index.js';

describe('builtin /model command', () => {
  it('passes through the full argument string', async () => {
    const cmd = createModelCommand();
    const setModel = vi.fn(() => 'ok');

    const result = await cmd.execute(['default', 'github/gpt-5-mini'], {
      channel: 'test',
      senderId: 'user',
      sessionId: 's1',
      rawInput: '/model default github/gpt-5-mini',
      services: { setModel },
    });

    expect(setModel).toHaveBeenCalledWith('default github/gpt-5-mini');
    expect(result).toEqual({ handled: true, text: 'ok' });
  });

  it('still works for single-argument tier switching', async () => {
    const cmd = createModelCommand();
    const setModel = vi.fn(() => 'switched');

    const result = await cmd.execute(['fast'], {
      channel: 'test',
      senderId: 'user',
      sessionId: 's1',
      rawInput: '/model fast',
      services: { setModel },
    });

    expect(setModel).toHaveBeenCalledWith('fast');
    expect(result).toEqual({ handled: true, text: 'switched' });
  });
});

describe('builtin /elevate command', () => {
  it('passes through the full argument string', async () => {
    const cmd = createElevateCommand();
    const setElevation = vi.fn(() => 'ok');

    const result = await cmd.execute(['10m', 'reason', '--yes'], {
      channel: 'test',
      senderId: 'user',
      sessionId: 's1',
      rawInput: '/elevate 10m reason --yes',
      services: { setElevation },
    });

    expect(setElevation).toHaveBeenCalledWith('10m reason --yes');
    expect(result).toEqual({ handled: true, text: 'ok' });
  });

  it('shows status when no args are provided', async () => {
    const cmd = createElevateCommand();
    const getElevation = vi.fn(() => 'status');
    const result = await cmd.execute([], {
      channel: 'test',
      senderId: 'user',
      sessionId: 's1',
      rawInput: '/elevate',
      services: { getElevation },
    });
    expect(getElevation).toHaveBeenCalledOnce();
    expect(result).toEqual({ handled: true, text: 'status' });
  });
});
