// tools/compliance-gate-handler.ts — Compliance gate configuration handler (SPEC-447)
import { z } from 'zod';
import { getComplianceGateConfig, saveComplianceGateConfig, } from '../storage/compliance-gate-config-store.js';
import { hashProjectPath } from '../storage/base-store.js';
// ---------------------------------------------------------------------------
// Zod schema (exported for use in register-compliance-gate-tools.ts)
// ---------------------------------------------------------------------------
export const ConfigureComplianceGateSchema = z.object({
    projectPath: z.string().describe('Absolute path to the project root'),
    mode: z
        .enum(['soft', 'hard'])
        .describe('Gate mode. Valid values: soft (warn only), hard (block transition if score < threshold).'),
    threshold: z
        .number()
        .min(0)
        .max(100)
        .default(90)
        .describe('Compliance score threshold (0–100). Default: 90.'),
});
// ---------------------------------------------------------------------------
// configure_compliance_gate
// ---------------------------------------------------------------------------
export async function handleConfigureComplianceGate(params) {
    const { projectPath, mode, threshold } = params;
    const projectId = hashProjectPath(projectPath);
    await saveComplianceGateConfig(projectId, { mode, threshold });
    return {
        content: [
            {
                type: 'text',
                text: `Compliance gate configured.\nMode: ${mode}\nThreshold: ${String(threshold)}/100\n` +
                    `When a spec is sent to review, compliance is checked. In '${mode}' mode, ` +
                    `${mode === 'hard' ? 'the transition is blocked' : 'a warning is shown'} if score < ${String(threshold)}.`,
            },
        ],
    };
}
// ---------------------------------------------------------------------------
// compliance_gate_status
// ---------------------------------------------------------------------------
export async function handleComplianceGateStatus(params) {
    const { projectPath } = params;
    const projectId = hashProjectPath(projectPath);
    const config = await getComplianceGateConfig(projectId);
    if (!config) {
        return {
            content: [
                {
                    type: 'text',
                    text: 'Compliance gate is not configured (using defaults: mode=soft, threshold=90).',
                },
            ],
        };
    }
    return {
        content: [
            {
                type: 'text',
                text: `Compliance gate is configured.\nMode: ${config.mode}\nThreshold: ${String(config.threshold)}/100`,
            },
        ],
    };
}
//# sourceMappingURL=compliance-gate-handler.js.map