'use server';
import { resolve } from '../../lib/server-container.js';
export async function getFeaturePlan(featureId) {
    if (!featureId.trim()) {
        return { error: 'Feature id is required' };
    }
    try {
        const repo = resolve('IFeatureRepository');
        const feature = await repo.findById(featureId);
        if (!feature) {
            return { error: 'Feature not found' };
        }
        if (!feature.plan) {
            return { plan: undefined };
        }
        const plan = {
            state: feature.plan.state,
            overview: feature.plan.overview,
            tasks: feature.plan.tasks.map((t) => ({
                title: t.title ?? '',
                description: t.description ?? '',
                state: t.state,
                actionItems: (t.actionItems ?? []).map((ai) => ({
                    name: ai.name,
                    description: ai.description,
                    acceptanceCriteria: (ai.acceptanceCriteria ?? []).map((ac) => ({
                        description: ac.description,
                        verified: ac.verified,
                    })),
                })),
            })),
        };
        return { plan };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to load feature plan';
        return { error: message };
    }
}
