"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PolicyEngineSchema = exports.PolicySchema = exports.ValidationModeSchema = exports.PolicyNameSchema = exports.PolicyEngineNameSchema = void 0;
const zod_util_1 = require("../zod-util");
const tags_1 = require("./tags");
const zod_1 = require("zod");
// ============================================================================
// Policy Engine Name Schema
// ============================================================================
/**
 * Policy engine name validation.
 * Pattern: ^[A-Za-z][A-Za-z0-9_]*$ max 48
 * Must begin with a letter, alphanumeric + underscores only.
 * @see API docs: PolicyEngine name constraints
 */
exports.PolicyEngineNameSchema = zod_1.z
    .string()
    .min(1, 'Policy engine name is required')
    .max(48, 'Policy engine name must be 48 characters or less')
    .regex(/^[A-Za-z][A-Za-z0-9_]{0,47}$/, 'Must begin with a letter and contain only alphanumeric characters and underscores (max 48 chars)');
// ============================================================================
// Policy Name Schema
// ============================================================================
/**
 * Policy name validation.
 * Pattern: [A-Za-z][A-Za-z0-9_]* min 1, max 48
 * Must begin with a letter, alphanumeric + underscores only.
 * @see API docs: Policy name constraints
 */
exports.PolicyNameSchema = zod_1.z
    .string()
    .min(1, 'Policy name is required')
    .max(48, 'Policy name must be 48 characters or less')
    .regex(/^[A-Za-z][A-Za-z0-9_]{0,47}$/, 'Must begin with a letter and contain only alphanumeric characters and underscores (max 48 chars)');
// ============================================================================
// Validation Mode Schema
// ============================================================================
exports.ValidationModeSchema = zod_1.z.enum(['FAIL_ON_ANY_FINDINGS', 'IGNORE_ALL_FINDINGS']);
// ============================================================================
// Policy Schema
// ============================================================================
exports.PolicySchema = zod_1.z.object({
    name: exports.PolicyNameSchema,
    description: zod_1.z.string().min(1).max(4096).optional(),
    statement: zod_1.z.string().min(1, 'Cedar policy statement is required'),
    sourceFile: zod_1.z.string().optional(),
    validationMode: exports.ValidationModeSchema.default('FAIL_ON_ANY_FINDINGS'),
});
// ============================================================================
// Policy Engine Schema
// ============================================================================
exports.PolicyEngineSchema = zod_1.z.object({
    name: exports.PolicyEngineNameSchema,
    description: zod_1.z.string().min(1).max(4096).optional(),
    encryptionKeyArn: zod_1.z.string().optional(),
    tags: tags_1.TagsSchema.optional(),
    policies: zod_1.z
        .array(exports.PolicySchema)
        .default([])
        .superRefine((0, zod_util_1.uniqueBy)(policy => policy.name, name => `Duplicate policy name: ${name}`)),
});
//# sourceMappingURL=policy.js.map