'use server';
import { resolve } from '../../lib/server-container.js';
export async function listComments(workItemId) {
    if (!workItemId?.trim()) {
        return { error: 'Work item ID is required' };
    }
    try {
        const useCase = resolve('ManageCommentsUseCase');
        const comments = await useCase.list(workItemId);
        return { comments };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list comments';
        return { error: message };
    }
}
export async function createComment(input) {
    try {
        const useCase = resolve('ManageCommentsUseCase');
        const result = await useCase.create(input);
        if (!result.ok)
            return { error: result.error };
        return { comment: result.comment };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create comment';
        return { error: message };
    }
}
export async function updateComment(commentId, content) {
    if (!commentId?.trim()) {
        return { error: 'Comment ID is required' };
    }
    try {
        const useCase = resolve('ManageCommentsUseCase');
        const result = await useCase.update(commentId, content);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to update comment';
        return { error: message };
    }
}
export async function deleteComment(commentId) {
    if (!commentId?.trim()) {
        return { error: 'Comment ID is required' };
    }
    try {
        const useCase = resolve('ManageCommentsUseCase');
        const result = await useCase.delete(commentId);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to delete comment';
        return { error: message };
    }
}
