import { describe, it, expect } from 'vitest';
import { setupADRTools } from '../tools.js';

describe('ADR Management Module', () => {
  describe('Tool Registration', () => {
    it('should register all ADR tools', async () => {
      const result = await setupADRTools();

      expect(result.module).toBe('adr-management');
      expect(result.tools).toBeDefined();
      expect(result.tools.length).toBeGreaterThan(0);
      
      const toolNames = result.tools.map(t => t.name);
      expect(toolNames).toContain('create_adr');
      expect(toolNames).toContain('create_adr_interactive');
      expect(toolNames).toContain('update_adr');
      expect(toolNames).toContain('link_adrs');
      expect(toolNames).toContain('get_adr');
      expect(toolNames).toContain('list_adrs');
      expect(toolNames).toContain('search_adrs');
      expect(toolNames).toContain('delete_adr');
      expect(toolNames).toContain('adr_metrics');
      expect(toolNames).toContain('validate_adr_references');
      expect(toolNames).toContain('generate_adr_log');
    });

    it('should have properly configured tool schemas', async () => {
      const result = await setupADRTools();

      // Test create_adr tool schema
      const createADRTool = result.tools.find(t => t.name === 'create_adr');
      expect(createADRTool).toBeDefined();
      expect(createADRTool!.description).toContain('Create a new Architecture Decision Record');
      expect(createADRTool!.inputSchema).toBeDefined();
      expect(createADRTool!.inputSchema.properties).toHaveProperty('title');
      expect(createADRTool!.inputSchema.properties).toHaveProperty('deciders');
      expect(createADRTool!.inputSchema.properties).toHaveProperty('context');
      expect(createADRTool!.inputSchema.properties).toHaveProperty('decision');
      expect(createADRTool!.inputSchema.properties).toHaveProperty('consequences');

      // Test get_adr tool schema
      const getADRTool = result.tools.find(t => t.name === 'get_adr');
      expect(getADRTool).toBeDefined();
      expect(getADRTool!.description).toContain('Get details of a specific Architecture Decision Record');
      expect(getADRTool!.inputSchema.properties).toHaveProperty('id');
    });

    it('should mark read-only tools correctly', async () => {
      const result = await setupADRTools();

      const readOnlyTools = ['get_adr', 'list_adrs', 'search_adrs', 'adr_metrics', 'validate_adr_references', 'generate_adr_log'];
      
      for (const toolName of readOnlyTools) {
        const tool = result.tools.find(t => t.name === toolName);
        expect(tool).toBeDefined();
        // Note: readOnly is checked in the tool execution, not in the registration
      }
    });

    it('should have correct ADR tool categories', async () => {
      const result = await setupADRTools();

      for (const tool of result.tools) {
        // All ADR tools should have the 'adr' category
        expect(tool.name).toMatch(/adr/);
      }
    });
  });
});