import { z } from 'zod';
import { FEATURE_ID_ENUM } from './featureIds.js';
export const FeatureStateSchema = z.enum(['enabled', 'disabled', 'unsupported', 'unknown']);
export const FeatureAxisSchema = z.enum(['client', 'build_policy', 'local_policy', 'server', 'daemon', 'scope', 'dependency']);
export const FeatureBlockerCodeSchema = z.enum([
    'none',
    'not_implemented',
    'build_disabled',
    'flag_disabled',
    'endpoint_missing',
    'feature_disabled',
    'capability_missing',
    'probe_failed',
    'mixed_scope_support',
    'misconfigured',
    'dependency_disabled',
    'dependency_unknown',
]);
export const FeatureDecisionScopeSchema = z.object({
    scopeKind: z.enum(['runtime', 'main_selection', 'spawn']),
    serverId: z.string().min(1).optional(),
    machineId: z.string().min(1).optional(),
});
export const FeatureDecisionSchema = z
    .object({
    featureId: z.enum(FEATURE_ID_ENUM),
    state: FeatureStateSchema,
    blockedBy: FeatureAxisSchema.nullable(),
    blockerCode: FeatureBlockerCodeSchema,
    diagnostics: z.array(z.string()),
    evaluatedAt: z.number().int().nonnegative(),
    scope: FeatureDecisionScopeSchema,
})
    .superRefine((value, ctx) => {
    if (value.state === 'enabled') {
        if (value.blockedBy !== null) {
            ctx.addIssue({
                code: z.ZodIssueCode.custom,
                path: ['blockedBy'],
                message: 'enabled feature decisions must not have blockedBy set',
            });
        }
        if (value.blockerCode !== 'none') {
            ctx.addIssue({
                code: z.ZodIssueCode.custom,
                path: ['blockerCode'],
                message: 'enabled feature decisions must use blockerCode=none',
            });
        }
    }
});
export function createFeatureDecision(input) {
    return FeatureDecisionSchema.parse(input);
}
//# sourceMappingURL=decision.js.map