'use server';
import { resolve } from '../../lib/server-container.js';
export async function listProjectRelations(projectId) {
    if (!projectId?.trim()) {
        return { error: 'Project ID is required' };
    }
    try {
        const listItems = resolve('ListWorkItemsUseCase');
        const listRelations = resolve('ListWorkItemRelationsUseCase');
        const items = await listItems.execute(projectId);
        const allRelations = new Map();
        for (const item of items) {
            const rels = await listRelations.execute(item.id);
            for (const rel of rels) {
                allRelations.set(rel.id, rel);
            }
        }
        return { relations: Array.from(allRelations.values()) };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list project relations';
        return { error: message };
    }
}
