import { describe, it, expect, vi } from 'vitest';
import { createMessageHandler, isAllowedChat } from './handlers.js';
import type { NativeAgent } from '../../backends/native/agent.js';

describe('isAllowedChat', () => {
  it('returns true for allowed chat ID', () => {
    expect(isAllowedChat(123, [123, 456])).toBe(true);
  });

  it('returns false for disallowed chat ID', () => {
    expect(isAllowedChat(789, [123, 456])).toBe(false);
  });
});

describe('createMessageHandler', () => {
  it('processes message and returns response', async () => {
    const mockAgent: NativeAgent = {
      process: vi.fn().mockResolvedValue('Agent response'),
      reset: vi.fn(),
      getHistory: vi.fn(),
    } as unknown as NativeAgent;

    const handler = createMessageHandler(mockAgent);
    const response = await handler('Hello');

    expect(response).toBe('Agent response');
    expect(mockAgent.process).toHaveBeenCalledWith('Hello');
  });
});
