// engine/execution-plan/phases.ts — Execution phase generators
// SRP: each function generates steps for one phase of the implementation plan.
// OCP: new phases can be added without modifying the dispatcher in generate-execution-plan.ts.
import { inferDataLayerFiles, inferServiceFiles, inferApiFiles, inferPageFiles, inferComponentFiles, } from './plan-utils.js';
export { generateTestingPhase, generateIntegrationPhase } from './phases-b.js';
export function generateSetupPhase(spec, knowledge, startOrder) {
    const steps = [];
    let order = startOrder;
    steps.push({
        order: order++,
        title: 'Create feature branch',
        description: `Create branch from main: ${spec.gitBranch || `feature/${spec.slug}`}`,
        files: [],
        dependsOn: [],
        verification: `Branch exists and is checked out: git branch --show-current`,
        estimatedMinutes: 2,
        canRollback: true,
    });
    if (knowledge.language === 'typescript' || knowledge.language === 'javascript') {
        steps.push({
            order: order++,
            title: 'Define types and interfaces',
            description: 'Create TypeScript interfaces for the new entities and API contracts',
            files: [`src/types/${spec.slug}.ts`],
            dependsOn: [startOrder],
            verification: 'TypeScript compiles without errors: npm run build',
            estimatedMinutes: 15,
            canRollback: true,
        });
    }
    if (spec.scope === 'cross-module' || spec.scope === 'architectural') {
        steps.push({
            order: order,
            title: 'Update project configuration',
            description: 'Add new configuration entries, feature flags, or environment variables',
            files: ['.env.example'],
            dependsOn: [startOrder],
            verification: 'Configuration values are documented and have defaults',
            estimatedMinutes: 10,
            canRollback: true,
        });
    }
    return steps;
}
export function generateDataLayerPhase(spec, knowledge, content, startOrder) {
    const steps = [];
    let order = startOrder;
    const lower = content.toLowerCase();
    if (lower.includes('table') ||
        lower.includes('schema') ||
        lower.includes('model') ||
        lower.includes('entity') ||
        lower.includes('migration') ||
        knowledge.database !== 'unknown') {
        steps.push({
            order: order++,
            title: 'Create database migration',
            description: `Create migration for new tables/columns in ${knowledge.database}`,
            files: [`migrations/${spec.slug}.sql`],
            dependsOn: [startOrder - 1],
            verification: 'Migration runs successfully: apply and rollback both work',
            estimatedMinutes: 20,
            canRollback: true,
        });
        steps.push({
            order: order++,
            title: 'Run migration on development database',
            description: 'Apply migration and verify schema changes',
            files: [],
            dependsOn: [order - 2],
            verification: 'Database schema matches expected state',
            estimatedMinutes: 5,
            canRollback: true,
        });
    }
    const lastStep = steps[steps.length - 1];
    steps.push({
        order: order++,
        title: 'Implement data access layer',
        description: 'Create repository/model functions for CRUD operations',
        files: inferDataLayerFiles(spec, knowledge),
        dependsOn: lastStep ? [lastStep.order] : [startOrder - 1],
        verification: 'Data access functions compile. Write unit tests for basic CRUD.',
        estimatedMinutes: 30,
        canRollback: true,
    });
    if (lower.includes('seed') || lower.includes('fixture') || lower.includes('sample data')) {
        steps.push({
            order: order++,
            title: 'Create seed data',
            description: 'Add seed/fixture data for development and testing',
            files: [`seeds/${spec.slug}.ts`],
            dependsOn: [order - 2],
            verification: 'Seed command runs without errors',
            estimatedMinutes: 15,
            canRollback: true,
        });
    }
    return steps;
}
export function generateBusinessLogicPhase(spec, knowledge, content, startOrder) {
    const steps = [];
    let order = startOrder;
    const lower = content.toLowerCase();
    steps.push({
        order: order++,
        title: 'Implement business logic',
        description: 'Create service/use-case functions with core domain logic',
        files: inferServiceFiles(spec, knowledge),
        dependsOn: [startOrder - 1],
        verification: 'Business logic functions pass unit tests with valid and invalid inputs',
        estimatedMinutes: 45,
        canRollback: true,
    });
    if (lower.includes('validat') || lower.includes('input') || lower.includes('form')) {
        steps.push({
            order: order++,
            title: 'Implement input validation',
            description: 'Add validation schemas for all inputs (Zod/Joi/class-validator)',
            files: [`src/validators/${spec.slug}.ts`],
            dependsOn: [startOrder],
            verification: 'Validation rejects invalid inputs with clear error messages',
            estimatedMinutes: 20,
            canRollback: true,
        });
    }
    if (lower.includes('api') ||
        lower.includes('endpoint') ||
        lower.includes('route') ||
        spec.target === 'backend' ||
        spec.target === 'fullstack') {
        steps.push({
            order: order++,
            title: 'Create API endpoints',
            description: 'Implement REST/GraphQL/tRPC endpoints with request handling',
            files: inferApiFiles(spec, knowledge),
            dependsOn: [startOrder],
            verification: 'Endpoints respond correctly: test with curl or HTTP client',
            estimatedMinutes: 30,
            canRollback: true,
        });
    }
    steps.push({
        order: order++,
        title: 'Add error handling',
        description: 'Implement structured error handling, logging, and error responses',
        files: [],
        dependsOn: [order - 2],
        verification: 'Error cases return proper status codes and error messages',
        estimatedMinutes: 15,
        canRollback: true,
    });
    return steps;
}
export function generateUIPhase(spec, knowledge, content, startOrder) {
    const steps = [];
    let order = startOrder;
    const lower = content.toLowerCase();
    const framework = knowledge.framework ?? 'react';
    steps.push({
        order: order++,
        title: 'Create page layout and routing',
        description: `Set up page structure and routes in ${framework}`,
        files: inferPageFiles(spec, knowledge),
        dependsOn: [startOrder - 1],
        verification: 'Page renders without errors. Route is accessible.',
        estimatedMinutes: 20,
        canRollback: true,
    });
    steps.push({
        order: order++,
        title: 'Build UI components',
        description: 'Implement reusable components (forms, lists, cards, etc.)',
        files: inferComponentFiles(spec, knowledge),
        dependsOn: [startOrder],
        verification: 'Components render correctly with mock data',
        estimatedMinutes: 45,
        canRollback: true,
    });
    steps.push({
        order: order++,
        title: 'Connect data fetching',
        description: 'Wire components to API, add loading and error states',
        files: [],
        dependsOn: [order - 2, order - 1],
        verification: 'Data loads from API. Loading spinners show. Errors display correctly.',
        estimatedMinutes: 30,
        canRollback: true,
    });
    if (lower.includes('form') ||
        lower.includes('create') ||
        lower.includes('edit') ||
        lower.includes('input')) {
        steps.push({
            order: order++,
            title: 'Implement form handling and validation',
            description: 'Add form state management, client-side validation, and submission',
            files: [],
            dependsOn: [order - 2],
            verification: 'Form submits successfully. Validation errors show inline. Submit button disables during submission.',
            estimatedMinutes: 25,
            canRollback: true,
        });
    }
    steps.push({
        order: order++,
        title: 'Add responsive design and accessibility',
        description: 'Ensure UI works on mobile, tablet, and desktop. Add ARIA labels.',
        files: [],
        dependsOn: [order - 2],
        verification: 'UI passes basic responsive checks. No accessibility violations on axe/Lighthouse.',
        estimatedMinutes: 20,
        canRollback: true,
    });
    return steps;
}
//# sourceMappingURL=phases.js.map