"use strict";
/**
 * Zod schema for runtime validation of workflows
 * Updated for flexible stack system
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkflowSchema = void 0;
const zod_1 = require("zod");
// Actor schema
const ActorSchema = zod_1.z.object({
    type: zod_1.z.string(),
    role: zod_1.z.string(),
});
// Workflow relationship schema
const WorkflowRelationshipSchema = zod_1.z.object({
    workflow: zod_1.z.string(),
    type: zod_1.z.enum(['prerequisite', 'dependent', 'related']),
    reason: zod_1.z.string(),
});
// Workflow config schema
const WorkflowConfigSchema = zod_1.z.object({
    packageManager: zod_1.z.enum(['npm', 'yarn', 'pnpm', 'bun']).optional(),
    nodeVersion: zod_1.z.string().optional(),
}).passthrough(); // Allow additional config options
// Workflow metadata schema
const WorkflowMetadataSchema = zod_1.z.object({
    id: zod_1.z.string().min(1, 'Workflow ID is required - use a unique identifier like "user-authentication" or "task-management"'),
    version: zod_1.z.string().min(1, 'Version is required - use semantic versioning like "1.0.0"'),
    name: zod_1.z.string().min(1, 'Name is required - provide a human-readable name for your workflow'),
    description: zod_1.z.string().min(1, 'Description is required - explain what this workflow does'),
    domains: zod_1.z.array(zod_1.z.string()).optional(),
    actors: zod_1.z.array(ActorSchema).optional(),
    relationships: zod_1.z.array(WorkflowRelationshipSchema).optional(),
    config: WorkflowConfigSchema.optional(),
});
// Validation rule schema
const ValidationRuleSchema = zod_1.z.object({
    required: zod_1.z.boolean().optional(),
    format: zod_1.z.string().optional(),
    minLength: zod_1.z.number().optional(),
    maxLength: zod_1.z.number().optional(),
    pattern: zod_1.z.string().optional(),
    custom: zod_1.z.string().optional(),
});
// Field schema
const FieldSchema = zod_1.z.object({
    id: zod_1.z.string(),
    type: zod_1.z.string(),
    label: zod_1.z.string(),
    placeholder: zod_1.z.string().optional(),
    validation: zod_1.z.array(ValidationRuleSchema).optional(),
});
// UI spec schema
const UISpecSchema = zod_1.z.object({
    layout: zod_1.z.string().optional(),
    fields: zod_1.z.array(FieldSchema).optional(),
});
// State definition schema
const StateDefinitionSchema = zod_1.z.object({
    name: zod_1.z.string(),
    type: zod_1.z.string(),
    initial: zod_1.z.any(),
});
// Step schema (flexible to support different action types)
const StepSchema = zod_1.z.object({
    id: zod_1.z.string(),
    action: zod_1.z.string(),
    depends_on: zod_1.z.array(zod_1.z.string()).optional(),
}).passthrough(); // Allow additional properties
// Action schema
const ActionSchema = zod_1.z.object({
    id: zod_1.z.string(),
    trigger: zod_1.z.string(),
    description: zod_1.z.string().optional(), // Optional - can be inferred from id
    steps: zod_1.z.array(StepSchema).optional(), // Optional - if not provided, generates scaffold only
});
// Generate options schema
const GenerateOptionsSchema = zod_1.z.object({
    styling: zod_1.z.string().optional(),
    testing: zod_1.z.boolean().optional(),
    storybook: zod_1.z.boolean().optional(),
    accessibility: zod_1.z.string().optional(),
});
// Component schema (for UI components)
const ComponentSchema = zod_1.z.object({
    id: zod_1.z.string(),
    type: zod_1.z.string().optional(), // Optional - can be inferred from parent context
    name: zod_1.z.string(),
    description: zod_1.z.string().optional(), // Optional - can be minimal scaffold
    ui: UISpecSchema.optional(),
    state: zod_1.z.array(StateDefinitionSchema).optional(),
    actions: zod_1.z.array(ActionSchema).optional(),
    generate: GenerateOptionsSchema.optional(),
});
// Property schema
const PropertySchemaSchema = zod_1.z.object({
    type: zod_1.z.string(),
    format: zod_1.z.string().optional(),
    description: zod_1.z.string().optional(),
    example: zod_1.z.any().optional(),
    enum: zod_1.z.array(zod_1.z.any()).optional(),
});
// Schema schema (for request/response bodies)
const SchemaSchema = zod_1.z.lazy(() => zod_1.z.object({
    type: zod_1.z.string(),
    required: zod_1.z.array(zod_1.z.string()).optional(),
    properties: zod_1.z.record(PropertySchemaSchema).optional(),
}));
// Request spec schema
const RequestSpecSchema = zod_1.z.object({
    body: SchemaSchema.optional(),
    query: SchemaSchema.optional(),
    params: SchemaSchema.optional(),
    headers: SchemaSchema.optional(),
});
// Response spec schema
const ResponseSpecSchema = zod_1.z.object({
    status: zod_1.z.number(),
    description: zod_1.z.string(),
    body: SchemaSchema.optional(),
});
// Implementation schema
const ImplementationSchema = zod_1.z.object({
    steps: zod_1.z.array(StepSchema),
});
// Middleware schema
const MiddlewareSchema = zod_1.z.record(zod_1.z.any());
// Endpoint schema (for API endpoints)
const EndpointSchema = zod_1.z.object({
    id: zod_1.z.string(),
    path: zod_1.z.string(),
    method: zod_1.z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']),
    name: zod_1.z.string(),
    description: zod_1.z.string(),
    request: RequestSpecSchema.optional(),
    responses: zod_1.z.array(ResponseSpecSchema),
    implementation: ImplementationSchema.optional(),
    middleware: zod_1.z.array(MiddlewareSchema).optional(),
    generate: GenerateOptionsSchema.optional(),
});
// Field definition schema (for database tables)
const FieldDefinitionSchema = zod_1.z.object({
    name: zod_1.z.string(),
    type: zod_1.z.string(),
    primary_key: zod_1.z.boolean().optional(),
    unique: zod_1.z.boolean().optional(),
    indexed: zod_1.z.boolean().optional(),
    foreign_key: zod_1.z.string().optional(),
    nullable: zod_1.z.boolean().optional(),
    default: zod_1.z.any().optional(),
});
// Table schema (for database)
const TableSchema = zod_1.z.object({
    name: zod_1.z.string(),
    description: zod_1.z.string(),
    required_fields: zod_1.z.array(FieldDefinitionSchema),
});
// Component workflow schema
const ComponentWorkflowSchema = zod_1.z.object({
    id: zod_1.z.string(),
    name: zod_1.z.string(),
    description: zod_1.z.string(),
    steps: zod_1.z.array(StepSchema),
});
// CLI Command Argument schema
const CommandArgumentSchema = zod_1.z.object({
    name: zod_1.z.string(),
    description: zod_1.z.string().optional(),
    required: zod_1.z.boolean().optional(),
    default: zod_1.z.any().optional(),
});
// CLI Command Option schema
const CommandOptionSchema = zod_1.z.object({
    name: zod_1.z.string(),
    alias: zod_1.z.string().optional(),
    description: zod_1.z.string().optional(),
    type: zod_1.z.string().optional(),
});
// CLI Command schema
const CommandSchema = zod_1.z.object({
    id: zod_1.z.string(),
    name: zod_1.z.string().optional(),
    description: zod_1.z.string().optional(),
    arguments: zod_1.z.array(CommandArgumentSchema).optional(),
    options: zod_1.z.array(CommandOptionSchema).optional(),
    implementation: ImplementationSchema.optional(),
});
// Expected dependency schema (for version management)
const ExpectedDependencySchema = zod_1.z.object({
    service: zod_1.z.string(),
    usage: zod_1.z.string(),
    required: zod_1.z.boolean().optional(),
});
// Stack Component schema - flexible, can contain different things based on type
const StackComponentSchema = zod_1.z.object({
    type: zod_1.z.string({ required_error: 'Stack component type is required - use "frontend", "backend", "database", etc.' }), // completely customizable
    technology: zod_1.z.string({ required_error: 'Technology is required - specify the framework or tool to use (e.g., "react", "express", "prisma")' }),
    description: zod_1.z.string().optional(),
    config: zod_1.z.record(zod_1.z.any()).optional(),
    dependsOn: zod_1.z.array(zod_1.z.string()).optional(),
    components: zod_1.z.array(ComponentSchema).optional(), // For frontend-like components
    endpoints: zod_1.z.array(EndpointSchema).optional(), // For backend-like components
    tables: zod_1.z.array(TableSchema).optional(), // For database-like components
    workflows: zod_1.z.array(ComponentWorkflowSchema).optional(), // Component-specific workflows
    commands: zod_1.z.array(CommandSchema).optional(), // For CLI components
    // Service routing configuration
    routing: zod_1.z.enum(['primary_only', 'context_based', 'load_balanced']).optional(),
    primary: zod_1.z.string().optional(),
    services: zod_1.z.record(zod_1.z.any()).optional(), // Service configurations with routing, weights, etc.
    // Version management
    expected_dependencies: zod_1.z.array(ExpectedDependencySchema).optional(),
});
// Stack components - keyed by component name
const StackComponentsSchema = zod_1.z.record(StackComponentSchema);
// Code example schema
const CodeExampleSchema = zod_1.z.object({
    language: zod_1.z.string(),
    code: zod_1.z.string(),
});
// Doc content schema
const DocContentSchema = zod_1.z.object({
    heading: zod_1.z.string(),
    content: zod_1.z.string(),
    steps: zod_1.z.array(zod_1.z.string()).optional(),
    examples: zod_1.z.array(CodeExampleSchema).optional(),
});
// Doc section schema
const DocSectionSchema = zod_1.z.object({
    title: zod_1.z.string(),
    sections: zod_1.z.array(DocContentSchema),
});
// Documentation schema
const DocumentationSchema = zod_1.z.object({
    user_docs: zod_1.z.array(DocSectionSchema).optional(),
    developer_docs: zod_1.z.array(DocSectionSchema).optional(),
});
// Unit test schema
const UnitTestSchema = zod_1.z.object({
    component: zod_1.z.string(),
    scenarios: zod_1.z.array(zod_1.z.string()),
});
// Integration test schema
const IntegrationTestSchema = zod_1.z.object({
    name: zod_1.z.string(),
    description: zod_1.z.string().optional(),
    steps: zod_1.z.array(zod_1.z.string()),
});
// E2E test schema
const E2ETestSchema = zod_1.z.object({
    name: zod_1.z.string(),
    tool: zod_1.z.string(),
    steps: zod_1.z.array(zod_1.z.string()),
});
// Testing schema
const _TestingSchema = zod_1.z.object({
    unit_tests: zod_1.z.array(UnitTestSchema).optional(),
    integration_tests: zod_1.z.array(IntegrationTestSchema).optional(),
    e2e_tests: zod_1.z.array(E2ETestSchema).optional(),
});
// Environment config schema - now keyed by component name
const EnvironmentConfigSchema = zod_1.z.record(zod_1.z.record(zod_1.z.string()));
// Environment schema
const EnvironmentSchema = zod_1.z.record(EnvironmentConfigSchema);
// Health check schema
const HealthCheckSchema = zod_1.z.object({
    path: zod_1.z.string(),
    interval: zod_1.z.string().optional(),
});
// Deployment config schema
const DeploymentConfigSchema = zod_1.z.object({
    build_command: zod_1.z.string().optional(),
    start_command: zod_1.z.string().optional(),
    output_directory: zod_1.z.string().optional(),
    health_check: HealthCheckSchema.optional(),
    environment_variables: zod_1.z.array(zod_1.z.string()).optional(),
});
// Deployment schema - now keyed by component name
const _DeploymentSchema = zod_1.z.record(DeploymentConfigSchema);
// Service instance schema (for infrastructure services)
const ServiceInstanceSchema = zod_1.z.object({
    provider: zod_1.z.string(),
    connection: zod_1.z.string(),
    config: zod_1.z.record(zod_1.z.any()).optional(),
});
// Worker config schema
const WorkerConfigSchema = zod_1.z.object({
    enabled: zod_1.z.boolean().optional(),
    concurrency: zod_1.z.number().optional(),
    queues: zod_1.z.array(zod_1.z.string()).optional(),
    config: zod_1.z.record(zod_1.z.any()).optional(),
});
// Stage config schema
const StageConfigSchema = zod_1.z.object({
    log_level: zod_1.z.enum(['debug', 'info', 'warn', 'error']).optional(),
    development_tools: zod_1.z.boolean().optional(),
    error_details: zod_1.z.boolean().optional(),
    cors: zod_1.z.object({
        enabled: zod_1.z.boolean().optional(),
        origins: zod_1.z.array(zod_1.z.string()).optional(),
    }).optional(),
    rate_limiting: zod_1.z.object({
        enabled: zod_1.z.boolean().optional(),
        requests_per_minute: zod_1.z.number().optional(),
    }).optional(),
    custom: zod_1.z.record(zod_1.z.any()).optional(),
});
// Stage infrastructure schema
const StageInfrastructureSchema = zod_1.z.object({
    domains: zod_1.z.object({
        web: zod_1.z.string().optional(),
        api: zod_1.z.string().optional(),
        docs: zod_1.z.string().optional(),
        portal: zod_1.z.string().optional(),
        admin: zod_1.z.string().optional(),
        marketing: zod_1.z.string().optional(),
        custom: zod_1.z.record(zod_1.z.string()).optional(),
    }).optional(),
    databases: zod_1.z.object({
        primary: zod_1.z.string(),
        analytics: zod_1.z.string().optional(),
        cache: zod_1.z.string().optional(),
        custom: zod_1.z.record(zod_1.z.string()).optional(),
    }),
    services: zod_1.z.object({
        redis: ServiceInstanceSchema.optional(),
        queue: ServiceInstanceSchema.optional(),
        storage: ServiceInstanceSchema.optional(),
        search: ServiceInstanceSchema.optional(),
        email: ServiceInstanceSchema.optional(),
        cdn: ServiceInstanceSchema.optional(),
        monitoring: ServiceInstanceSchema.optional(),
        custom: zod_1.z.record(ServiceInstanceSchema).optional(),
    }).optional(),
    workers: WorkerConfigSchema.optional(),
});
// Stage schema
const StageSchema = zod_1.z.object({
    description: zod_1.z.string().optional(),
    infrastructure: StageInfrastructureSchema,
    config: StageConfigSchema.optional(),
    env: zod_1.z.record(zod_1.z.string()).optional(),
});
// Stages schema - keyed by stage name
const StagesSchema = zod_1.z.record(StageSchema);
// ===== ENHANCED SCHEMA: Cross-Cutting Concerns =====
// Technology configuration
const TechnologySchema = zod_1.z.object({
    backend: zod_1.z.object({
        framework: zod_1.z.string().optional(),
        language: zod_1.z.string().optional(),
    }).optional(),
    frontend: zod_1.z.object({
        framework: zod_1.z.string().optional(),
        styling: zod_1.z.string().optional(),
    }).optional(),
    database: zod_1.z.string().optional(),
}).passthrough();
// Testing framework configuration
const TestFrameworkConfigSchema = zod_1.z.object({
    tool: zod_1.z.enum(['vitest', 'jest', 'mocha', 'ava']).optional(),
    config: zod_1.z.record(zod_1.z.any()).optional(),
    pattern: zod_1.z.string().optional(),
}).passthrough();
const E2ETestConfigSchema = zod_1.z.object({
    tool: zod_1.z.enum(['playwright', 'cypress', 'puppeteer']).optional(),
    config: zod_1.z.record(zod_1.z.any()).optional(),
    browsers: zod_1.z.array(zod_1.z.string()).optional(),
}).passthrough();
const CoverageThresholdSchema = zod_1.z.object({
    statements: zod_1.z.number().optional(),
    branches: zod_1.z.number().optional(),
    functions: zod_1.z.number().optional(),
    lines: zod_1.z.number().optional(),
});
const ExternalApiMockSchema = zod_1.z.object({
    service: zod_1.z.string(),
    base_url: zod_1.z.string(),
    handlers: zod_1.z.array(zod_1.z.string()).optional(),
});
const TestFixturesSchema = zod_1.z.object({
    path: zod_1.z.string().optional(),
    auto_load: zod_1.z.boolean().optional(),
});
const FactoryConfigSchema = zod_1.z.object({
    tool: zod_1.z.enum(['faker', 'fishery', 'factory_bot']).optional(),
    path: zod_1.z.string().optional(),
});
// Enhanced Testing schema
const EnhancedTestingSchema = zod_1.z.object({
    frameworks: zod_1.z.object({
        unit: TestFrameworkConfigSchema.optional(),
        integration: TestFrameworkConfigSchema.optional(),
        e2e: E2ETestConfigSchema.optional(),
        component: TestFrameworkConfigSchema.optional(),
    }).optional(),
    coverage: zod_1.z.object({
        threshold: zod_1.z.object({
            global: CoverageThresholdSchema.optional(),
            per_file: CoverageThresholdSchema.optional(),
        }).optional(),
        exclude: zod_1.z.array(zod_1.z.string()).optional(),
    }).optional(),
    database: zod_1.z.object({
        strategy: zod_1.z.enum(['testcontainers', 'sqlite', 'dedicated', 'mock']),
        reset_strategy: zod_1.z.enum(['truncate', 'drop_and_recreate']).optional(),
        fixtures_path: zod_1.z.string().optional(),
    }).optional(),
    workers: zod_1.z.object({
        strategy: zod_1.z.enum(['mock_queue', 'test_redis', 'in_memory']),
        auto_process: zod_1.z.boolean().optional(),
    }).optional(),
    external_apis: zod_1.z.object({
        strategy: zod_1.z.enum(['msw', 'nock', 'mock_server']),
        handlers_path: zod_1.z.string().optional(),
        mock_definitions: zod_1.z.array(ExternalApiMockSchema).optional(),
    }).optional(),
    ci_cd: zod_1.z.object({
        provider: zod_1.z.enum(['github_actions', 'gitlab_ci', 'circle_ci']).optional(),
        test_on_pr: zod_1.z.boolean().optional(),
        test_requirements: zod_1.z.object({
            require_passing: zod_1.z.boolean().optional(),
            minimum_coverage: zod_1.z.number().optional(),
        }).optional(),
    }).optional(),
    fixtures: TestFixturesSchema.optional(),
    factories: FactoryConfigSchema.optional(),
    // Legacy format support
    unit_tests: zod_1.z.array(UnitTestSchema).optional(),
    integration_tests: zod_1.z.array(IntegrationTestSchema).optional(),
    e2e_tests: zod_1.z.array(E2ETestSchema).optional(),
}).passthrough();
// Monitoring configuration
const LogTransportSchema = zod_1.z.object({
    type: zod_1.z.enum(['console', 'file', 'http', 'syslog']),
    config: zod_1.z.record(zod_1.z.any()).optional(),
});
const MetricDefinitionSchema = zod_1.z.object({
    name: zod_1.z.string(),
    type: zod_1.z.enum(['counter', 'gauge', 'histogram']),
    description: zod_1.z.string().optional(),
});
const AlertDefinitionSchema = zod_1.z.object({
    name: zod_1.z.string(),
    condition: zod_1.z.string(),
    severity: zod_1.z.enum(['low', 'medium', 'high', 'critical']),
    channels: zod_1.z.array(zod_1.z.string()).optional(),
});
const MonitoringSchema = zod_1.z.object({
    apm: zod_1.z.object({
        provider: zod_1.z.string(),
        config: zod_1.z.record(zod_1.z.any()).optional(),
    }).optional(),
    error_tracking: zod_1.z.object({
        provider: zod_1.z.string(),
        config: zod_1.z.record(zod_1.z.any()).optional(),
        frontend: zod_1.z.boolean().optional(),
        backend: zod_1.z.boolean().optional(),
    }).optional(),
    logging: zod_1.z.object({
        provider: zod_1.z.string(),
        level: zod_1.z.enum(['debug', 'info', 'warn', 'error']),
        transports: zod_1.z.array(LogTransportSchema).optional(),
    }).optional(),
    tracing: zod_1.z.object({
        provider: zod_1.z.string(),
        sampling_rate: zod_1.z.number().optional(),
    }).optional(),
    metrics: zod_1.z.object({
        tracked: zod_1.z.array(zod_1.z.string()),
        custom_metrics: zod_1.z.array(MetricDefinitionSchema).optional(),
    }).optional(),
    alerts: zod_1.z.array(AlertDefinitionSchema).optional(),
}).passthrough();
// Security configuration
const DataRetentionPolicySchema = zod_1.z.object({
    user_data: zod_1.z.string().optional(),
    logs: zod_1.z.string().optional(),
    backups: zod_1.z.string().optional(),
});
const GDPRConfigSchema = zod_1.z.object({
    data_export: zod_1.z.boolean().optional(),
    right_to_be_forgotten: zod_1.z.boolean().optional(),
    consent_management: zod_1.z.boolean().optional(),
});
const RateLimitingConfigSchema = zod_1.z.object({
    enabled: zod_1.z.boolean(),
    default_limit: zod_1.z.string().optional(),
    per_endpoint: zod_1.z.record(zod_1.z.string()).optional(),
});
const SecuritySchema = zod_1.z.object({
    compliance: zod_1.z.object({
        regulations: zod_1.z.array(zod_1.z.enum(['gdpr', 'ccpa', 'hipaa', 'soc2', 'pci_dss'])),
        data_retention: DataRetentionPolicySchema.optional(),
        gdpr: GDPRConfigSchema.optional(),
    }).optional(),
    encryption: zod_1.z.object({
        at_rest: zod_1.z.boolean(),
        in_transit: zod_1.z.boolean(),
        field_level: zod_1.z.array(zod_1.z.string()).optional(),
    }).optional(),
    audit_logging: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        retention: zod_1.z.string(),
        log_all_database_changes: zod_1.z.boolean().optional(),
        log_api_requests: zod_1.z.boolean().optional(),
    }).optional(),
    csp: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        directives: zod_1.z.record(zod_1.z.array(zod_1.z.string())).optional(),
    }).optional(),
    rate_limiting: RateLimitingConfigSchema.optional(),
}).passthrough();
// Performance configuration
const PerformanceSchema = zod_1.z.object({
    frontend: zod_1.z.object({
        code_splitting: zod_1.z.enum(['route_based', 'component_based', 'manual']).optional(),
        lazy_loading: zod_1.z.boolean().optional(),
        tree_shaking: zod_1.z.boolean().optional(),
        bundle_budget: zod_1.z.object({
            max_initial: zod_1.z.string().optional(),
            max_total: zod_1.z.string().optional(),
        }).optional(),
    }).optional(),
    backend: zod_1.z.object({
        caching: zod_1.z.object({
            strategy: zod_1.z.enum(['redis', 'memcached', 'in_memory']),
            ttl: zod_1.z.number().optional(),
            cache_keys: zod_1.z.array(zod_1.z.string()).optional(),
        }).optional(),
        connection_pooling: zod_1.z.object({
            min: zod_1.z.number(),
            max: zod_1.z.number(),
            idle_timeout: zod_1.z.number().optional(),
        }).optional(),
        query_optimization: zod_1.z.boolean().optional(),
    }).optional(),
    database: zod_1.z.object({
        read_replicas: zod_1.z.number().optional(),
        sharding: zod_1.z.object({
            strategy: zod_1.z.enum(['by_tenant', 'by_date', 'by_hash']),
            shard_count: zod_1.z.number().optional(),
        }).optional(),
        indexing_strategy: zod_1.z.enum(['auto', 'manual']).optional(),
    }).optional(),
    cdn: zod_1.z.object({
        provider: zod_1.z.string(),
        assets: zod_1.z.array(zod_1.z.string()).optional(),
        cache_ttl: zod_1.z.number().optional(),
    }).optional(),
}).passthrough();
// Internationalization configuration
const InternationalizationSchema = zod_1.z.object({
    default_locale: zod_1.z.string(),
    supported_locales: zod_1.z.array(zod_1.z.string()),
    translation_files: zod_1.z.string().optional(),
    fallback_strategy: zod_1.z.enum(['cascade', 'default']).optional(),
    formatting: zod_1.z.object({
        dates: zod_1.z.enum(['locale_specific', 'iso']).optional(),
        numbers: zod_1.z.enum(['locale_specific', 'standard']).optional(),
        currency: zod_1.z.enum(['locale_specific', 'usd']).optional(),
    }).optional(),
    translation_management: zod_1.z.object({
        provider: zod_1.z.string().optional(),
        auto_sync: zod_1.z.boolean().optional(),
    }).optional(),
}).passthrough();
// Feature flags configuration
const FeatureFlagsSchema = zod_1.z.object({
    provider: zod_1.z.string(),
    flags: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        enabled: zod_1.z.boolean(),
        rollout_percentage: zod_1.z.number().optional(),
        rollout_strategy: zod_1.z.enum(['gradual', 'immediate']).optional(),
        targeting: zod_1.z.object({
            user_segments: zod_1.z.array(zod_1.z.string()).optional(),
        }).optional(),
        schedule: zod_1.z.array(zod_1.z.object({
            date: zod_1.z.string(),
            percentage: zod_1.z.number(),
        })).optional(),
    })).optional(),
}).passthrough();
// Access control configuration
const AccessControlSchema = zod_1.z.object({
    model: zod_1.z.enum(['rbac', 'abac', 'rbac_with_abac']),
    roles: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        permissions: zod_1.z.array(zod_1.z.object({
            resource: zod_1.z.string(),
            actions: zod_1.z.array(zod_1.z.string()),
            conditions: zod_1.z.array(zod_1.z.object({
                field: zod_1.z.string(),
                operator: zod_1.z.enum(['equals', 'contains', 'gt', 'lt']),
                value: zod_1.z.any(),
            })).optional(),
        })),
    })).optional(),
    policies: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        resource: zod_1.z.string(),
        action: zod_1.z.string(),
        rules: zod_1.z.array(zod_1.z.object({
            role: zod_1.z.string().optional(),
            condition: zod_1.z.string().optional(),
        })),
    })).optional(),
}).passthrough();
// API configuration
const ApiConfigurationSchema = zod_1.z.object({
    base_path: zod_1.z.string().optional(),
    documentation: zod_1.z.object({
        format: zod_1.z.enum(['openapi', 'swagger', 'graphql_schema']),
        auto_generate: zod_1.z.boolean(),
        output: zod_1.z.string().optional(),
    }).optional(),
    versioning: zod_1.z.object({
        strategy: zod_1.z.enum(['url_path', 'header', 'query_param']),
        deprecation_policy: zod_1.z.object({
            notice_period: zod_1.z.string(),
            sunset_headers: zod_1.z.boolean(),
        }).optional(),
    }).optional(),
    cors: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        origins: zod_1.z.array(zod_1.z.string()).optional(),
        methods: zod_1.z.array(zod_1.z.string()).optional(),
        credentials: zod_1.z.boolean().optional(),
    }).optional(),
    middleware: zod_1.z.array(zod_1.z.string()).optional(),
    endpoints: zod_1.z.array(zod_1.z.any()).optional(), // Complex Endpoint type
}).passthrough();
// Deployment configuration
const DeploymentConfigurationSchema = zod_1.z.object({
    strategy: zod_1.z.enum(['single_region', 'multi_region', 'edge']),
    regions: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        primary: zod_1.z.boolean().optional(),
        services: zod_1.z.array(zod_1.z.string()),
        database_replica: zod_1.z.boolean().optional(),
    })).optional(),
    edge_functions: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        regions: zod_1.z.union([zod_1.z.literal('all'), zod_1.z.array(zod_1.z.string())]),
        provider: zod_1.z.string().optional(),
    })).optional(),
    geo_routing: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        strategy: zod_1.z.enum(['lowest_latency', 'closest_region', 'manual']),
    }).optional(),
    disaster_recovery: zod_1.z.object({
        rpo: zod_1.z.string(),
        rto: zod_1.z.string(),
        replica_regions: zod_1.z.array(zod_1.z.string()).optional(),
        failover: zod_1.z.enum(['automatic', 'manual']),
    }).optional(),
}).passthrough();
// Analytics configuration
const AnalyticsSchema = zod_1.z.object({
    provider: zod_1.z.string(),
    tracking: zod_1.z.object({
        auto_track: zod_1.z.array(zod_1.z.string()).optional(),
        custom_events: zod_1.z.array(zod_1.z.object({
            name: zod_1.z.string(),
            properties: zod_1.z.array(zod_1.z.string()),
        })).optional(),
    }).optional(),
    funnels: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        steps: zod_1.z.array(zod_1.z.object({
            event: zod_1.z.string(),
            required: zod_1.z.boolean().optional(),
        })),
    })).optional(),
    cohorts: zod_1.z.array(zod_1.z.object({
        name: zod_1.z.string(),
        criteria: zod_1.z.string(),
    })).optional(),
}).passthrough();
// Models configuration (for data layer)
const ModelsSchema = zod_1.z.record(zod_1.z.any()).optional();
// Migrations configuration
const MigrationsSchema = zod_1.z.object({
    tool: zod_1.z.enum(['prisma', 'knex', 'typeorm', 'sequelize']).optional(),
    path: zod_1.z.string().optional(),
}).passthrough().optional();
// Workflow definitions (business logic workflows)
const WorkflowDefinitionsSchema = zod_1.z.record(zod_1.z.any()).optional();
// Events configuration
const EventsSchema = zod_1.z.record(zod_1.z.any()).optional();
// Complete workflow schema with flexible stack and enhanced sections
exports.WorkflowSchema = zod_1.z.object({
    workflow: WorkflowMetadataSchema,
    technology: TechnologySchema.optional(),
    // === CROSS-CUTTING CONCERNS (Top-Level) ===
    testing: EnhancedTestingSchema.optional(),
    monitoring: MonitoringSchema.optional(),
    security: SecuritySchema.optional(),
    performance: PerformanceSchema.optional(),
    i18n: InternationalizationSchema.optional(),
    feature_flags: FeatureFlagsSchema.optional(),
    access_control: AccessControlSchema.optional(),
    api: ApiConfigurationSchema.optional(),
    deployment: DeploymentConfigurationSchema.optional(),
    analytics: AnalyticsSchema.optional(),
    // === COMPONENTS (Service-Specific) ===
    stack: StackComponentsSchema, // New flexible stack system
    // === DATA LAYER ===
    models: ModelsSchema,
    migrations: MigrationsSchema,
    // === BUSINESS LOGIC ===
    workflows: WorkflowDefinitionsSchema,
    events: EventsSchema,
    // === ENVIRONMENTS ===
    stages: StagesSchema.optional(), // Multi-stage infrastructure configuration
    // === LEGACY/OPTIONAL ===
    documentation: DocumentationSchema.optional(),
    environment: EnvironmentSchema.optional(),
}).refine((data) => Object.keys(data.stack).length > 0, {
    message: 'Workflow must define at least one stack component (e.g., frontend, backend, database). Example: stack:\n  frontend:\n    type: frontend\n    technology: react',
});
//# sourceMappingURL=workflow-schema.js.map