/**
 * Default Policy Templates
 *
 * Pre-configured MissionPolicy templates for common use cases.
 * These are re-exported from the types layer for convenience,
 * with additional factory helpers for creating policies from templates.
 *
 * @module services/policy/default-policies
 */
import { CONSERVATIVE_POLICY, MODERATE_POLICY, AUTONOMOUS_POLICY, CONSERVATIVE_CADENCE, createMissionPolicy, } from '../../types/v2/index.js';
/** All valid template names. */
export const POLICY_TEMPLATE_NAMES = [
    'conservative',
    'moderate',
    'autonomous',
];
/**
 * Checks whether a string is a valid policy template name.
 *
 * @param value - The string to check
 * @returns True if value is a valid PolicyTemplateName
 */
export function isValidPolicyTemplateName(value) {
    return POLICY_TEMPLATE_NAMES.includes(value);
}
// ---------------------------------------------------------------------------
// Template Descriptions (for UI/API)
// ---------------------------------------------------------------------------
/**
 * Human-readable descriptions of each policy template.
 */
export const POLICY_TEMPLATE_DESCRIPTIONS = {
    conservative: 'All capabilities disabled. Every action requires human approval. Best for new or high-risk missions.',
    moderate: 'Can create, reprioritize, and close tasks. No deploy or spending. Good for established teams with clear scope.',
    autonomous: 'Most capabilities enabled except production deploy and UI changes without review. For trusted teams with guardrails.',
};
// ---------------------------------------------------------------------------
// Factory Helpers
// ---------------------------------------------------------------------------
/**
 * Creates a policy from a template name, optionally applying overrides.
 *
 * @param missionId - The mission this policy belongs to
 * @param template - Template name
 * @param overrides - Optional field overrides
 * @returns A fully populated MissionPolicy
 *
 * @example
 * ```typescript
 * const policy = createPolicyFromTemplate('mission-1', 'moderate', {
 *   canDeployToStaging: true,
 *   maxParallelExecutions: 5,
 * });
 * ```
 */
export function createPolicyFromTemplate(missionId, template, overrides) {
    const base = createMissionPolicy(missionId, template);
    if (!overrides)
        return base;
    const { executionCadence: cadenceOverrides, ...restOverrides } = overrides;
    return {
        ...base,
        ...restOverrides,
        missionId, // Ensure missionId is never overridden
        escalationRules: overrides.escalationRules ?? base.escalationRules,
        executionCadence: cadenceOverrides && base.executionCadence
            ? { ...base.executionCadence, ...cadenceOverrides }
            : cadenceOverrides
                ? { ...CONSERVATIVE_CADENCE, ...cadenceOverrides }
                : base.executionCadence,
    };
}
/**
 * Applies partial updates to an existing policy.
 * Preserves missionId and any fields not in the update.
 *
 * @param existing - The current policy
 * @param updates - Fields to update
 * @returns Updated policy (new object, doesn't mutate)
 */
export function applyPolicyUpdate(existing, updates) {
    const { executionCadence: cadenceUpdates, ...restUpdates } = updates;
    return {
        ...existing,
        ...restUpdates,
        missionId: existing.missionId, // Never overwrite missionId
        escalationRules: updates.escalationRules ?? existing.escalationRules,
        executionCadence: cadenceUpdates && existing.executionCadence
            ? { ...existing.executionCadence, ...cadenceUpdates }
            : cadenceUpdates
                ? { ...CONSERVATIVE_CADENCE, ...cadenceUpdates }
                : existing.executionCadence,
    };
}
/**
 * Returns a summary of what a policy allows/blocks, for display purposes.
 *
 * @param policy - The policy to summarize
 * @returns Object with allowed and blocked action lists
 */
export function summarizePolicy(policy) {
    const gates = [
        ['Create tasks', policy.canCreateTasks],
        ['Reprioritize tasks', policy.canReprioritizeTasks],
        ['Close tasks', policy.canCloseTasks],
        ['Deploy to staging', policy.canDeployToStaging],
        ['Deploy to production', policy.canDeployToProd],
        ['Spend money', policy.canSpendMoney],
        ['Change user-visible behavior', policy.canChangeUserVisibleBehaviorWithoutReview],
    ];
    return {
        allowed: gates.filter(([, v]) => v).map(([k]) => k),
        blocked: gates.filter(([, v]) => !v).map(([k]) => k),
        maxParallel: policy.maxParallelExecutions,
        escalationCount: policy.escalationRules.length,
    };
}
// Re-export template constants for convenience
export { CONSERVATIVE_POLICY, MODERATE_POLICY, AUTONOMOUS_POLICY };
//# sourceMappingURL=default-policies.js.map