import { setLocale, isSupportedLocale, ti } from '../i18n/index.js';
import { globalStore, knowledgeStore } from '../storage/index.js';
export async function handleSetLocale(params) {
    const { locale, projectId } = params;
    if (!isSupportedLocale(locale)) {
        return {
            content: [
                { type: 'text', text: ti('locale.unsupported', { locale, available: 'en, es, pt' }) },
            ],
            isError: true,
        };
    }
    // Set the runtime locale
    setLocale(locale);
    // If projectId is provided, update the project knowledge locale
    if (projectId) {
        const knowledge = await knowledgeStore.getKnowledge(projectId);
        if (knowledge) {
            await knowledgeStore.updateKnowledge(projectId, { locale: locale });
        }
    }
    // Update global default locale
    await globalStore.setDefaultLocale(locale);
    const result = {
        locale,
        projectId: projectId ?? null,
        globalDefault: true,
        message: ti('locale.changed', { locale }),
    };
    return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
    };
}
//# sourceMappingURL=set-locale.js.map