import { z } from 'zod';
import { t } from '../../i18n/index.js';
import { safeTracked, safeLicensed } from '../safe-handler.js';
import { SupportedLocaleEnum, SpecStatusEnum, SpecTypeEnum, SpecScopeEnum, SpecTargetEnum, ExperienceLevelEnum, } from '../schemas/index.js';
import { handleSetLocale } from '../set-locale.js';
import { handleInitProject } from '../init-project.js';
import { handleInitConstitution } from '../init-constitution.js';
import { handleClarifyRequirements } from '../clarify-requirements.js';
import { handleCreateSpec } from '../create-spec.js';
import { handleListSpecs } from '../list-specs.js';
import { handleUpdateStatus } from '../update-status.js';
import { handleEstimate } from '../estimate.js';
import { handleReverseEngineer } from '../reverse-engineer.js';
import { handleValidate } from '../validate.js';
/**
 * Registers core spec lifecycle tools (tools 1–10) on the MCP server.
 */
export function registerCoreSpecTools(server) {
    // 1. set_locale
    server.registerTool('set_locale', {
        description: t('tools.set_locale.description'),
        inputSchema: {
            locale: SupportedLocaleEnum.describe('Target locale (en, es, pt)'),
            projectId: z.string().optional().describe('Optional project ID to set locale per-project'),
        },
    }, safeTracked('set_locale', async (args) => handleSetLocale(args)));
    // 2. init_project
    server.registerTool('init_project', {
        description: t('tools.init_project.description'),
        inputSchema: {
            projectPath: z.string().describe('Absolute path to the project root'),
            locale: SupportedLocaleEnum.optional().describe('Preferred locale for this project'),
            hourlyRate: z
                .number()
                .optional()
                .describe('Developer hourly rate in USD for cost estimation'),
            experienceLevel: ExperienceLevelEnum.optional().describe('Developer experience level: beginner, intermediate, or expert'),
            userProfile: z
                .enum(['developer', 'product-owner', 'designer', 'non-technical'])
                .optional()
                .describe('User profile type — determines how detailed and technical Planu interactions will be. Ask the user before running init_project.'),
        },
    }, safeTracked('init_project', async (args) => handleInitProject(args)));
    // 3. init_constitution
    server.registerTool('init_constitution', {
        description: t('tools.init_constitution.description'),
        inputSchema: {
            projectId: z.string().describe('Project ID'),
            autoDetect: z
                .boolean()
                .optional()
                .describe('Auto-detect principles from codebase (default: true)'),
            principles: z
                .array(z.object({
                id: z.string(),
                category: z.enum([
                    'architecture',
                    'security',
                    'quality',
                    'conventions',
                    'tech-stack',
                    'workflow',
                ]),
                principle: z.string(),
                rationale: z.string(),
                enforceLevel: z.enum(['strict', 'recommended']),
                autoEnforceable: z.boolean(),
                source: z.enum(['auto-detected', 'user-defined', 'claude-md', 'learned']),
                immutable: z.boolean(),
            }))
                .optional()
                .describe('Manual principles to include'),
        },
    }, safeTracked('init_constitution', async (args) => handleInitConstitution(args)));
    // 4. clarify_requirements
    server.registerTool('clarify_requirements', {
        description: t('tools.clarify_requirements.description'),
        inputSchema: {
            projectId: z.string().describe('Project ID'),
            topic: z.string().describe('The topic or feature to clarify'),
            context: z.string().optional().describe('Additional context about the requirement'),
            maxQuestions: z
                .number()
                .optional()
                .describe('Maximum number of questions to generate (default: 5)'),
        },
    }, safeTracked('clarify_requirements', async (args) => handleClarifyRequirements(args)));
    // 5. create_spec
    server.registerTool('create_spec', {
        description: t('tools.create_spec.description'),
        inputSchema: {
            title: z.string().describe('Title of the spec / user story'),
            description: z.string().describe('Detailed description of the feature or change'),
            projectPath: z.string().describe('Absolute path to the project root'),
            type: SpecTypeEnum.optional().describe('Spec type (default: feature)'),
            scope: SpecScopeEnum.optional().describe('Spec scope (default: feature)'),
            target: SpecTargetEnum.optional().describe('Target area: frontend, backend, shared, fullstack, infrastructure, database'),
            tags: z.array(z.string()).optional().describe('Tags for categorization'),
            feature: z
                .string()
                .optional()
                .describe('Feature group name (e.g. "Authentication", "Billing"). Specs are organized under {specLocation}/{feature}/. Defaults to _general.'),
        },
    }, safeTracked('create_spec', async (args) => handleCreateSpec(args)));
    // 6. list_specs
    server.registerTool('list_specs', {
        description: t('tools.list_specs.description'),
        inputSchema: {
            projectId: z.string().describe('Project ID'),
            status: SpecStatusEnum.optional().describe('Filter by spec status'),
            type: SpecTypeEnum.optional().describe('Filter by spec type'),
        },
    }, safeTracked('list_specs', async (args) => handleListSpecs(args)));
    // 7. update_status
    server.registerTool('update_status', {
        description: t('tools.update_status.description'),
        inputSchema: {
            specId: z.string().describe('Spec ID to update'),
            projectId: z.string().describe('Project ID'),
            status: SpecStatusEnum.describe('New status'),
            actuals: z
                .object({
                devHours: z.number(),
                reviewHours: z.number(),
                tokensOpus: z.number(),
                tokensSonnet: z.number(),
                apiCostUsd: z.number(),
                humanCostUsd: z.number(),
                totalCostUsd: z.number(),
                completedAt: z.string(),
                notes: z.string(),
            })
                .optional()
                .describe('Actual metrics (required when status = done)'),
            reviewNotes: z
                .string()
                .optional()
                .describe('Feedback or observations when sending a spec back (e.g., review→draft). Stored in the spec for the implementer to address.'),
        },
    }, safeTracked('update_status', async (args) => handleUpdateStatus(args)));
    // 8. estimate
    server.registerTool('estimate', {
        description: t('tools.estimate.description'),
        inputSchema: {
            specId: z.string().describe('Spec ID to estimate'),
            projectId: z.string().describe('Project ID'),
        },
    }, safeTracked('estimate', async (args) => handleEstimate(args)));
    // 9. reverse_engineer
    server.registerTool('reverse_engineer', {
        description: t('tools.reverse_engineer.description'),
        inputSchema: {
            path: z.string().describe('Path to the file or directory to analyze'),
            projectId: z.string().describe('Project ID'),
            depth: z.enum(['shallow', 'deep']).optional().describe('Analysis depth (default: shallow)'),
        },
    }, safeLicensed('reverse_engineer', async (args) => handleReverseEngineer(args)));
    // 10. validate
    server.registerTool('validate', {
        description: t('tools.validate.description'),
        inputSchema: {
            specId: z.string().describe('Spec ID to validate'),
            projectId: z.string().describe('Project ID'),
        },
    }, safeTracked('validate', async (args) => handleValidate(args)));
}
//# sourceMappingURL=core-spec-tools.js.map