import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { setupBootstrapModule } from '../index';

describe('Bootstrap Module', () => {
  let server: Server;

  beforeEach(async () => {
    server = new Server({
      name: 'test-server',
      version: '1.0.0'
    }, {
      capabilities: {
        tools: {}
      }
    });
  });

  describe('tool registration', () => {
    it('should register all bootstrap tools', async () => {
      const module = await setupBootstrapModule(server);
      
      expect(module.tools).toHaveLength(3);
      
      const toolNames = module.tools.map(t => t.name);
      expect(toolNames).toContain('bootstrap_analyze');
      expect(toolNames).toContain('bootstrap_plan');
      expect(toolNames).toContain('bootstrap_execute');
    });

    it('should have proper schemas for all tools', async () => {
      const module = await setupBootstrapModule(server);
      
      module.tools.forEach(tool => {
        expect(tool.description).toBeDefined();
        expect(tool.inputSchema).toBeDefined();
      });
    });

    it('should register analyze tool with correct schema', async () => {
      const module = await setupBootstrapModule(server);
      const analyzeTool = module.tools.find(t => t.name === 'bootstrap_analyze');
      
      expect(analyzeTool).toBeDefined();
      expect(analyzeTool?.description).toContain('Analyze current project state');
      expect(analyzeTool?.inputSchema).toHaveProperty('properties.projectPath');
    });

    it('should register plan tool with correct schema', async () => {
      const module = await setupBootstrapModule(server);
      const planTool = module.tools.find(t => t.name === 'bootstrap_plan');
      
      expect(planTool).toBeDefined();
      expect(planTool?.description).toContain('Create a bootstrap plan');
      expect(planTool?.inputSchema).toHaveProperty('properties.priority');
      expect(planTool?.inputSchema).toHaveProperty('properties.projectPath');
    });

    it('should register execute tool with correct schema', async () => {
      const module = await setupBootstrapModule(server);
      const executeTool = module.tools.find(t => t.name === 'bootstrap_execute');
      
      expect(executeTool).toBeDefined();
      expect(executeTool?.description).toContain('Execute selected bootstrap recommendations');
      expect(executeTool?.inputSchema).toHaveProperty('properties.recommendationIds');
      expect(executeTool?.inputSchema).toHaveProperty('properties.projectPath');
    });

    it('should return empty resources array', async () => {
      const module = await setupBootstrapModule(server);
      
      expect(module.resources).toBeDefined();
      expect(module.resources).toEqual([]);
    });
  });
});