import { InteractionManager } from '../interaction-framework/interaction-manager.js';
export class FeatureDiscoveryWizard {
    interactionManager;
    constructor() {
        this.interactionManager = new InteractionManager();
    }
    startFeatureDiscovery() {
        const steps = [
            // Step 1: Feature Name
            {
                id: 'featureName',
                type: 'question',
                questionType: 'text',
                prompt: '🎯 What feature would you like to build?',
                helpText: 'Give it a clear, descriptive name (e.g., "User Authentication", "Payment Processing")',
                required: true,
                validation: (value) => {
                    if (!value || value.trim().length < 3) {
                        return 'Feature name must be at least 3 characters long';
                    }
                    if (value.length > 100) {
                        return 'Feature name must be less than 100 characters';
                    }
                    return true;
                }
            },
            // Step 2: User Problem
            {
                id: 'userProblem',
                type: 'question',
                questionType: 'text',
                prompt: '🤔 What problem does this feature solve for users?',
                helpText: 'Describe the user pain point or need this addresses',
                required: true,
                validation: (value) => {
                    if (!value || value.trim().length < 20) {
                        return 'Please provide a detailed problem description (at least 20 characters)';
                    }
                    return true;
                }
            },
            // Step 3: User Story
            {
                id: 'userStory',
                type: 'question',
                questionType: 'text',
                prompt: '📖 Write a user story for this feature',
                helpText: 'Format: "As a [user type], I want to [action] so that [benefit]"',
                defaultValue: 'As a user, I want to ',
                required: true,
                validation: (value) => {
                    if (!value || value.trim().length < 20) {
                        return 'Please provide a complete user story';
                    }
                    if (!value.toLowerCase().includes('as a') || !value.toLowerCase().includes('i want')) {
                        return 'Please follow the user story format: "As a..., I want to..."';
                    }
                    return true;
                }
            },
            // Step 4: Success Criteria
            {
                id: 'successCriteria',
                type: 'question',
                questionType: 'text',
                prompt: '✅ How will you know this feature is successful?',
                helpText: 'List measurable success criteria (separate with semicolons)',
                required: true
            },
            // Step 5: Feature Type
            {
                id: 'featureType',
                type: 'question',
                questionType: 'multipleChoice',
                prompt: '🏗️ What type of feature is this?',
                options: [
                    'User Interface (Frontend)',
                    'Business Logic (Backend)',
                    'Data/Database',
                    'Integration/API',
                    'Infrastructure/DevOps',
                    'Cross-cutting (Multiple layers)'
                ],
                defaultValue: 'Cross-cutting (Multiple layers)',
                required: true
            },
            // Step 6: Technical Approach
            {
                id: 'technicalApproach',
                type: 'question',
                questionType: 'multipleChoice',
                prompt: '🔧 What\'s your initial technical approach?',
                helpText: 'This helps identify potential challenges early',
                options: [
                    'Build from scratch',
                    'Extend existing functionality',
                    'Integrate third-party service',
                    'Refactor existing code',
                    'Research needed first'
                ],
                defaultValue: 'Build from scratch',
                required: true
            },
            // Step 7: Complexity Estimate
            {
                id: 'complexity',
                type: 'question',
                questionType: 'multipleChoice',
                prompt: '📊 How complex is this feature?',
                helpText: 'Consider technical difficulty, unknowns, and integration points',
                options: [
                    'Simple (1-2 days)',
                    'Medium (3-5 days)',
                    'Complex (1-2 weeks)',
                    'Very Complex (2+ weeks)',
                    'Unknown (needs research)'
                ],
                defaultValue: 'Medium (3-5 days)',
                required: true
            },
            // Step 8: Dependencies
            {
                id: 'hasDependencies',
                type: 'question',
                questionType: 'yesNo',
                prompt: '🔗 Does this feature depend on other features or systems?',
                defaultValue: false
            },
            // Step 9: Dependencies Details (conditional)
            {
                id: 'dependencyDetails',
                type: 'question',
                questionType: 'text',
                prompt: '📝 What are the dependencies?',
                helpText: 'List other features, APIs, or systems this depends on',
                required: false,
                validation: (value, responses) => {
                    if (responses.hasDependencies === true && (!value || value.trim().length === 0)) {
                        return 'Please describe the dependencies';
                    }
                    return true;
                }
            },
            // Step 10: Acceptance Criteria
            {
                id: 'acceptanceCriteria',
                type: 'question',
                questionType: 'text',
                prompt: '📋 Define acceptance criteria',
                helpText: 'List specific, testable criteria (separate with semicolons). Example: "User can log in with email; Password is encrypted; Session expires after 24 hours"',
                required: true
            },
            // Step 11: Testing Strategy
            {
                id: 'testingStrategy',
                type: 'question',
                questionType: 'multipleChoice',
                prompt: '🧪 What\'s your testing approach?',
                helpText: 'How will you ensure this feature works correctly?',
                options: [
                    'Unit tests only',
                    'Unit + Integration tests',
                    'Unit + Integration + E2E tests',
                    'Manual testing only',
                    'TDD (Test-Driven Development)'
                ],
                defaultValue: 'Unit + Integration tests',
                required: true
            },
            // Step 12: Performance Considerations
            {
                id: 'hasPerformanceRequirements',
                type: 'question',
                questionType: 'yesNo',
                prompt: '⚡ Are there specific performance requirements?',
                helpText: 'Response time, throughput, scalability needs',
                defaultValue: false
            },
            // Step 13: Performance Details (conditional)
            {
                id: 'performanceDetails',
                type: 'question',
                questionType: 'text',
                prompt: '📈 Describe the performance requirements',
                helpText: 'Example: "API response < 200ms, Support 1000 concurrent users"',
                required: false
            },
            // Step 14: Security Considerations
            {
                id: 'securityConsiderations',
                type: 'question',
                questionType: 'text',
                prompt: '🔒 Are there any security considerations?',
                helpText: 'Authentication, authorization, data privacy, etc.',
                required: false
            },
            // Step 15: Review
            {
                id: 'review',
                type: 'review',
                prompt: '📋 Please review your feature definition',
                sections: [] // Will be populated dynamically
            },
            // Step 16: Confirmation
            {
                id: 'confirmation',
                type: 'confirmation',
                prompt: '✅ Ready to create the feature and start TDD?',
                summary: {}, // Will be populated dynamically
                editableFields: ['featureName', 'userStory', 'complexity']
            }
        ];
        const workflow = this.interactionManager.createWorkflow('Feature Discovery Wizard', 'Collaborative feature definition with user context and technical planning', steps);
        return workflow;
    }
    async processWorkflowResponse(workflowId, response) {
        const workflow = this.interactionManager.getWorkflow(workflowId);
        if (!workflow) {
            throw new Error('Workflow not found');
        }
        const currentStep = this.interactionManager.getCurrentStep(workflowId);
        // Skip dependency details if no dependencies
        if (currentStep?.id === 'hasDependencies' && response === false) {
            workflow.responses['dependencyDetails'] = 'N/A';
            workflow.currentStep++;
        }
        // Skip performance details if no requirements
        if (currentStep?.id === 'hasPerformanceRequirements' && response === false) {
            workflow.responses['performanceDetails'] = 'N/A';
            workflow.currentStep++;
        }
        // Process the response
        const result = await this.interactionManager.processResponse(workflowId, response);
        // Update review/confirmation steps with collected data
        if (result.nextStep?.id === 'review') {
            this.updateReviewStep(workflow);
        }
        else if (result.nextStep?.id === 'confirmation') {
            this.updateConfirmationStep(workflow);
        }
        return result;
    }
    updateReviewStep(workflow) {
        const reviewStep = workflow.steps.find((s) => s.id === 'review');
        const responses = workflow.responses;
        reviewStep.sections = [
            {
                title: '🎯 Feature Overview',
                content: `**Name**: ${responses.featureName}
**Type**: ${responses.featureType}
**Complexity**: ${responses.complexity}
**Technical Approach**: ${responses.technicalApproach}`,
                editable: true
            },
            {
                title: '👤 User Context',
                content: `**Problem**: ${responses.userProblem}
**User Story**: ${responses.userStory}
**Success Criteria**: ${responses.successCriteria}`,
                editable: true
            },
            {
                title: '✅ Acceptance Criteria',
                content: responses.acceptanceCriteria,
                editable: true
            },
            {
                title: '🧪 Quality Assurance',
                content: `**Testing Strategy**: ${responses.testingStrategy}
${responses.securityConsiderations ? `**Security**: ${responses.securityConsiderations}` : ''}
${responses.performanceDetails !== 'N/A' ? `**Performance**: ${responses.performanceDetails}` : ''}`,
                editable: false
            }
        ];
        if (responses.dependencyDetails !== 'N/A') {
            reviewStep.sections.push({
                title: '🔗 Dependencies',
                content: responses.dependencyDetails,
                editable: true
            });
        }
    }
    updateConfirmationStep(workflow) {
        const confirmStep = workflow.steps.find((s) => s.id === 'confirmation');
        const responses = workflow.responses;
        confirmStep.summary = {
            'Feature Name': responses.featureName,
            'User Story': responses.userStory,
            'Type': responses.featureType,
            'Complexity': responses.complexity,
            'Testing Strategy': responses.testingStrategy,
            'Has Dependencies': responses.hasDependencies ? 'Yes' : 'No'
        };
    }
    completeWorkflow(workflowId) {
        const result = this.interactionManager.completeWorkflow(workflowId);
        if (!result || !result.completed)
            return undefined;
        const responses = result.responses;
        // Parse success criteria
        const successCriteria = responses.successCriteria
            .split(';')
            .map((criterion) => criterion.trim())
            .filter((criterion) => criterion.length > 0);
        // Parse acceptance criteria
        const acceptanceCriteria = responses.acceptanceCriteria
            .split(';')
            .map((criterion) => criterion.trim())
            .filter((criterion) => criterion.length > 0);
        return {
            name: responses.featureName,
            description: `${responses.userProblem}\n\n${responses.userStory}`,
            userProblem: responses.userProblem,
            userStory: responses.userStory,
            successCriteria,
            acceptanceCriteria,
            featureType: responses.featureType,
            technicalApproach: responses.technicalApproach,
            complexity: responses.complexity,
            hasDependencies: responses.hasDependencies,
            dependencies: responses.dependencyDetails !== 'N/A' ? responses.dependencyDetails : undefined,
            testingStrategy: responses.testingStrategy,
            performanceRequirements: responses.performanceDetails !== 'N/A' ? responses.performanceDetails : undefined,
            securityConsiderations: responses.securityConsiderations,
            metadata: {
                createdVia: 'interactive-wizard',
                wizardVersion: '1.0'
            }
        };
    }
    formatCurrentStep(workflowId) {
        const workflow = this.interactionManager.getWorkflow(workflowId);
        if (!workflow)
            return 'Workflow not found';
        const currentStep = this.interactionManager.getCurrentStep(workflowId);
        if (!currentStep)
            return 'No current step';
        const progress = `Step ${workflow.currentStep + 1} of ${workflow.steps.length}`;
        const prompt = this.interactionManager.formatStepPrompt(currentStep);
        return `${progress}\n\n${prompt}`;
    }
    cancelWorkflow(workflowId) {
        return this.interactionManager.cancelWorkflow(workflowId);
    }
}
//# sourceMappingURL=feature-discovery-wizard.js.map