'use server';
import { resolve } from '../../lib/server-container.js';
export async function listLabels(projectId) {
    if (!projectId?.trim()) {
        return { error: 'Project ID is required' };
    }
    try {
        const useCase = resolve('ManageLabelsUseCase');
        const labels = await useCase.list(projectId);
        return { labels };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list labels';
        return { error: message };
    }
}
export async function createLabel(input) {
    try {
        const useCase = resolve('ManageLabelsUseCase');
        const result = await useCase.create(input);
        if (!result.ok)
            return { error: result.error };
        return { label: result.label };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create label';
        return { error: message };
    }
}
export async function updateLabel(labelId, fields) {
    if (!labelId?.trim()) {
        return { error: 'Label ID is required' };
    }
    try {
        const useCase = resolve('ManageLabelsUseCase');
        const result = await useCase.update(labelId, fields);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to update label';
        return { error: message };
    }
}
export async function deleteLabel(labelId) {
    if (!labelId?.trim()) {
        return { error: 'Label ID is required' };
    }
    try {
        const useCase = resolve('ManageLabelsUseCase');
        const result = await useCase.delete(labelId);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to delete label';
        return { error: message };
    }
}
