const PROJECTIONS = ["full", "overview", "queue", "status"];
export function parseDashboardSummaryProjection(args) {
    const raw = args?.projection;
    if (typeof raw === "string" && PROJECTIONS.includes(raw)) {
        return raw;
    }
    return "full";
}
export function dashboardSummaryNeedsQueueRollups(projection) {
    return projection === "full" || projection === "queue";
}
export function dashboardSummaryNeedsOverviewRollups(projection) {
    return projection === "full" || projection === "overview";
}
export function dashboardSummaryNeedsStatusRollups(projection) {
    return projection === "full" || projection === "status";
}
export function dashboardSummaryNeedsPastPhaseNotes(projection) {
    return projection === "full" || projection === "queue";
}
export function dashboardSummaryNeedsPhaseJournalStats(projection) {
    return projection === "full" || projection === "queue";
}
const emptyListSummary = () => ({ schemaVersion: 1, count: 0, top: [], phaseBuckets: [] });
const emptyWishlist = (pageSize) => ({
    schemaVersion: 1,
    openCount: 0,
    totalCount: 0,
    openPage: 0,
    openPageSize: pageSize,
    openTotalPages: 0,
    openTop: []
});
const emptyIdeas = () => ({
    schemaVersion: 1,
    available: false,
    totalCount: 0,
    openCount: 0,
    planningCount: 0,
    plannedCount: 0,
    top: []
});
const emptyPhaseJournalStats = () => ({
    schemaVersion: 1,
    available: false,
    phases: [],
    currentPhase: {
        phaseKey: null,
        activeNoteCount: 0,
        completedDeliveryTaskCount: 0,
        silenceWarning: false
    }
});
/** Stamp `dashboardProjection` and omit fields outside the requested slice (after builders ran). */
export function finalizeDashboardSummaryProjection(data, projection) {
    if (projection === "full") {
        return { ...data, dashboardProjection: "full" };
    }
    const base = {
        schemaVersion: data.schemaVersion,
        planningGeneration: data.planningGeneration,
        planningGenerationPolicy: data.planningGenerationPolicy,
        taskStoreLastUpdated: data.taskStoreLastUpdated,
        workspaceStatus: data.workspaceStatus,
        planArtifact: data.planArtifact,
        stateSummary: data.stateSummary,
        executionPlanningScope: data.executionPlanningScope,
        taskStateProjection: data.taskStateProjection,
        dashboardProjection: projection
    };
    if (projection === "overview") {
        return {
            ...base,
            planningSession: null,
            planArtifact: data.planArtifact,
            transcriptChurnResearchSummary: emptyListSummary(),
            proposedImprovementsSummary: emptyListSummary(),
            proposedExecutionSummary: emptyListSummary(),
            readyImprovementsSummary: emptyListSummary(),
            readyExecutionSummary: emptyListSummary(),
            readyQueueTop: [],
            readyQueueCount: 0,
            readyQueueBreakdown: { schemaVersion: 1, improvement: 0, other: 0 },
            wishlist: emptyWishlist(10),
            ideas: emptyIdeas(),
            blockedSummary: { count: 0, top: [], phaseBuckets: [] },
            humanGatesSummary: data.humanGatesSummary,
            approvalQueue: data.approvalQueue,
            phaseJournalStats: emptyPhaseJournalStats(),
            completedSummary: emptyListSummary(),
            cancelledSummary: emptyListSummary(),
            suggestedNext: data.suggestedNext,
            dependencyOverview: {
                schemaVersion: 1,
                activeTaskCount: 0,
                includedTaskCount: 0,
                edgeCount: 0,
                truncated: false,
                perfNote: "overview projection",
                nodes: [],
                edges: [],
                mermaidFlowchart: "",
                criticalPathReady: []
            },
            blockingAnalysis: [],
            agentGuidance: data.agentGuidance,
            teamExecution: data.teamExecution,
            subagentRegistry: data.subagentRegistry,
            taskCheckpoints: data.taskCheckpoints,
            systemStatus: data.systemStatus,
            taskStateProjection: data.taskStateProjection,
            agentStatus: data.agentStatus,
            currentPhaseDelivery: data.currentPhaseDelivery,
            deliveredPhaseKeys: data.deliveredPhaseKeys,
            rolledOutPhaseKeys: data.rolledOutPhaseKeys,
            phaseReleaseDates: data.phaseReleaseDates,
            legacyDeliveredMaxOrdinal: data.legacyDeliveredMaxOrdinal,
            phaseKeysWithActiveQueueWork: data.phaseKeysWithActiveQueueWork,
            pastPhaseNotes: []
        };
    }
    if (projection === "queue") {
        return {
            ...base,
            planningSession: data.planningSession,
            planArtifact: data.planArtifact,
            transcriptChurnResearchSummary: data.transcriptChurnResearchSummary,
            proposedImprovementsSummary: data.proposedImprovementsSummary,
            proposedExecutionSummary: data.proposedExecutionSummary,
            readyImprovementsSummary: data.readyImprovementsSummary,
            readyExecutionSummary: data.readyExecutionSummary,
            readyQueueTop: data.readyQueueTop,
            readyQueueCount: data.readyQueueCount,
            readyQueueBreakdown: data.readyQueueBreakdown,
            wishlist: data.wishlist,
            ideas: data.ideas,
            blockedSummary: data.blockedSummary,
            humanGatesSummary: data.humanGatesSummary,
            approvalQueue: data.approvalQueue,
            phaseJournalStats: data.phaseJournalStats,
            completedSummary: data.completedSummary,
            cancelledSummary: data.cancelledSummary,
            suggestedNext: data.suggestedNext,
            dependencyOverview: data.dependencyOverview,
            blockingAnalysis: data.blockingAnalysis,
            agentGuidance: null,
            teamExecution: data.teamExecution,
            subagentRegistry: data.subagentRegistry,
            taskCheckpoints: data.taskCheckpoints,
            systemStatus: data.systemStatus,
            taskStateProjection: data.taskStateProjection,
            agentStatus: data.agentStatus,
            currentPhaseDelivery: data.currentPhaseDelivery,
            deliveredPhaseKeys: data.deliveredPhaseKeys,
            rolledOutPhaseKeys: data.rolledOutPhaseKeys,
            phaseReleaseDates: data.phaseReleaseDates,
            legacyDeliveredMaxOrdinal: data.legacyDeliveredMaxOrdinal,
            phaseKeysWithActiveQueueWork: data.phaseKeysWithActiveQueueWork,
            pastPhaseNotes: data.pastPhaseNotes
        };
    }
    // status
    return {
        ...base,
        planningSession: data.planningSession,
        planArtifact: data.planArtifact,
        transcriptChurnResearchSummary: emptyListSummary(),
        proposedImprovementsSummary: emptyListSummary(),
        proposedExecutionSummary: emptyListSummary(),
        readyImprovementsSummary: emptyListSummary(),
        readyExecutionSummary: emptyListSummary(),
        readyQueueTop: [],
        readyQueueCount: 0,
        readyQueueBreakdown: { schemaVersion: 1, improvement: 0, other: 0 },
        wishlist: emptyWishlist(10),
        ideas: emptyIdeas(),
        blockedSummary: { count: 0, top: [], phaseBuckets: [] },
        humanGatesSummary: data.humanGatesSummary,
        approvalQueue: data.approvalQueue,
        phaseJournalStats: emptyPhaseJournalStats(),
        completedSummary: emptyListSummary(),
        cancelledSummary: emptyListSummary(),
        suggestedNext: data.suggestedNext,
        dependencyOverview: data.dependencyOverview,
        blockingAnalysis: [],
        agentGuidance: data.agentGuidance,
        teamExecution: data.teamExecution,
        subagentRegistry: data.subagentRegistry,
        taskCheckpoints: data.taskCheckpoints,
        systemStatus: data.systemStatus,
        taskStateProjection: data.taskStateProjection,
        agentStatus: data.agentStatus,
        currentPhaseDelivery: data.currentPhaseDelivery,
        deliveredPhaseKeys: data.deliveredPhaseKeys,
        rolledOutPhaseKeys: data.rolledOutPhaseKeys,
        phaseReleaseDates: data.phaseReleaseDates,
        legacyDeliveredMaxOrdinal: data.legacyDeliveredMaxOrdinal,
        phaseKeysWithActiveQueueWork: data.phaseKeysWithActiveQueueWork,
        pastPhaseNotes: []
    };
}
