'use server';
import { revalidatePath } from 'next/cache';
import { resolve } from '../../lib/server-container.js';
import { updateSettings as updateSettingsSingleton } from '../../../../../packages/core/src/infrastructure/services/settings.service.js';
export async function removeInjectedSkill(skillName) {
    try {
        const loadUseCase = resolve('LoadSettingsUseCase');
        const current = await loadUseCase.execute();
        const existingSkills = current.workflow.skillInjection?.skills ?? [];
        const filtered = existingSkills.filter((s) => s.name !== skillName);
        if (filtered.length === existingSkills.length) {
            return { success: false, error: `Skill "${skillName}" not found in configuration` };
        }
        const updated = {
            ...current,
            workflow: {
                ...current.workflow,
                skillInjection: {
                    enabled: current.workflow.skillInjection?.enabled ?? false,
                    skills: filtered,
                },
            },
            updatedAt: new Date(),
        };
        const updateUseCase = resolve('UpdateSettingsUseCase');
        await updateUseCase.execute(updated);
        updateSettingsSingleton(updated);
        revalidatePath('/skills');
        return { success: true };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to remove skill';
        return { success: false, error: message };
    }
}
