import { describe, it, expect } from 'vitest';
import type { Tool, ToolCall, ToolResult, ToolUseMessage, ToolResultMessage } from './types.js';

describe('Tool types', () => {
  it('Tool interface is structurally correct', () => {
    const tool: Tool = {
      name: 'test.echo',
      description: 'Echoes input',
      inputSchema: {
        type: 'object',
        properties: { text: { type: 'string' } },
        required: ['text'],
      },
      execute: async (args) => ({ success: true, output: String((args as { text: string }).text) }),
    };

    expect(tool.name).toBe('test.echo');
    expect(tool.inputSchema.type).toBe('object');
  });

  it('ToolCall has required fields', () => {
    const call: ToolCall = { id: 'call_1', name: 'test.echo', args: { text: 'hi' } };
    expect(call.id).toBe('call_1');
    expect(call.name).toBe('test.echo');
  });

  it('ToolResult has success and output', () => {
    const result: ToolResult = { success: true, output: 'hello' };
    expect(result.success).toBe(true);

    const errResult: ToolResult = { success: false, output: '', error: 'boom' };
    expect(errResult.error).toBe('boom');
  });

  it('ToolUseMessage has correct shape', () => {
    const msg: ToolUseMessage = {
      role: 'assistant',
      content: [{ type: 'tool_use', id: 'call_1', name: 'test.echo', input: { text: 'hi' } }],
    };
    expect(msg.role).toBe('assistant');
    expect(msg.content[0].type).toBe('tool_use');
  });

  it('ToolResultMessage has correct shape', () => {
    const msg: ToolResultMessage = {
      role: 'user',
      content: [{ type: 'tool_result', tool_use_id: 'call_1', content: 'output here' }],
    };
    expect(msg.role).toBe('user');
    expect(msg.content[0].type).toBe('tool_result');
  });
});
