'use server';
import { resolve } from '../../lib/server-container.js';
export async function createIntakeItem(input) {
    try {
        const useCase = resolve('CreateIntakeItemUseCase');
        const result = await useCase.execute(input);
        if (!result.ok)
            return { error: result.error };
        return { intakeItem: result.intakeItem };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create intake item';
        return { error: message };
    }
}
export async function listIntakeItems(projectId, status) {
    try {
        const useCase = resolve('ListIntakeItemsUseCase');
        const result = await useCase.execute({ projectId, status });
        return { items: result.items };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list intake items';
        return { error: message };
    }
}
export async function acceptIntakeItem(intakeItemId) {
    try {
        const useCase = resolve('AcceptIntakeItemUseCase');
        const result = await useCase.execute({ intakeItemId });
        if (!result.ok)
            return { error: result.error };
        return { workItem: result.workItem };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to accept intake item';
        return { error: message };
    }
}
export async function declineIntakeItem(intakeItemId, reason) {
    try {
        const useCase = resolve('DeclineIntakeItemUseCase');
        const result = await useCase.execute({ intakeItemId, reason });
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to decline intake item';
        return { error: message };
    }
}
export async function autoTriageIntakeItem(intakeItemId) {
    try {
        const useCase = resolve('AutoTriageIntakeItemUseCase');
        const result = await useCase.execute({ intakeItemId });
        if (!result.ok)
            return { error: result.error };
        return { suggestions: result.suggestions };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to auto-triage intake item';
        return { error: message };
    }
}
export async function detectDuplicates(intakeItemId) {
    try {
        const useCase = resolve('DetectDuplicatesUseCase');
        const result = await useCase.execute({ intakeItemId });
        if (!result.ok)
            return { error: result.error };
        return { candidates: result.candidates };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to detect duplicates';
        return { error: message };
    }
}
