'use server';
import { resolve } from '../../lib/server-container.js';
export async function approveFeature(featureId, payload) {
    if (!featureId.trim()) {
        return { approved: false, error: 'Feature id is required' };
    }
    try {
        const featureRepo = resolve('IFeatureRepository');
        const feature = await featureRepo.findById(featureId);
        if (!feature) {
            return { approved: false, error: 'Feature not found' };
        }
        if (!feature.agentRunId) {
            return { approved: false, error: 'Feature has no agent run' };
        }
        // Always use ApproveAgentRunUseCase — it handles waitingApproval, failed,
        // and interrupted statuses. This ensures approval is propagated via
        // Command({update: {_approvalAction: 'approved'}}) so the graph node
        // receives it on resume.
        const approveUseCase = resolve('ApproveAgentRunUseCase');
        const result = await approveUseCase.execute(feature.agentRunId, payload);
        if (!result.approved) {
            return { approved: false, error: result.reason };
        }
        return { approved: true };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to approve feature';
        return { approved: false, error: message };
    }
}
