import { describe, it, expect, beforeEach } from 'vitest';
import { setupDocumentationTools } from '../tools.js';
import { ToolRegistration } from '../../../core/types.js';

describe('Documentation Tools - 12-Factor MCP', () => {
  let toolRegistration: ToolRegistration;

  beforeEach(async () => {
    toolRegistration = await setupDocumentationTools();
  });

  it('should register all documentation tools', () => {
    expect(toolRegistration.module).toBe('documentation');
    expect(toolRegistration.tools).toHaveLength(6);
    
    const toolNames = toolRegistration.tools.map(t => t.name);
    expect(toolNames).toContain('generate_readme');
    expect(toolNames).toContain('generate_claude_config');
    expect(toolNames).toContain('create_documentation');
    expect(toolNames).toContain('list_documents');
    expect(toolNames).toContain('update_document');
    expect(toolNames).toContain('search_documents');
  });

  it('should have proper schema validation for all tools', () => {
    for (const tool of toolRegistration.tools) {
      expect(tool.inputSchema).toBeDefined();
      expect(tool.inputSchema.type).toBe('object');
      expect(tool.inputSchema.properties).toBeDefined();
      expect(tool.description).toBeDefined();
      expect(tool.category).toBe('documentation');
    }
  });

  it('should mark read-only tools correctly', () => {
    const readOnlyTools = ['list_documents', 'search_documents'];
    
    for (const tool of toolRegistration.tools) {
      if (readOnlyTools.includes(tool.name)) {
        expect(tool.readOnly).toBe(true);
      } else {
        expect(tool.readOnly).toBeFalsy(); // Can be false or undefined
      }
    }
  });
});