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6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
"""
Demo Scenarios for ARF 3.3.9 OSS vs Enterprise
Pre-built scenarios showing the difference between advisory and mechanical enforcement
"""

DEMO_SCENARIOS = {
    "database_drop": {
        "name": "High-Risk Database Operation",
        "action": "DROP DATABASE production CASCADE",
        "description": "Irreversible deletion of production database",
        "context": {
            "environment": "production",
            "criticality": "critical",
            "data_loss": "irreversible",
            "affected_users": 10000
        },
        "oss_result": {
            "risk_level": "High",
            "confidence": 0.95,
            "recommendation": "❌ DO NOT EXECUTE - High risk of irreversible data loss",
            "policy_violations": 2,
            "can_execute": False,
            "execution_status": "BLOCKED (Advisory)",
            "reason": "Violates high-risk database policy and irreversible action policy"
        },
        "enterprise_result": {
            "license_tier": "professional",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Professional license valid"},
                {"name": "risk_assessment", "required": True, "passed": False, "message": "Risk score 0.95 > 0.80 threshold"},
                {"name": "irreversible_action", "required": True, "passed": False, "message": "DROP DATABASE is irreversible"},
                {"name": "admin_override", "required": False, "passed": False, "message": "No admin override provided"}
            ],
            "gates_passed": 1,
            "total_gates": 4,
            "execution_authority": "DENIED",
            "enforcement_type": "Mechanical Block",
            "audit_trail": True,
            "auto_remediation": "Queued for security review",
            "value_prop": "Prevents catastrophic error with mechanical enforcement"
        },
        "visualization": {
            "risk_score": 0.95,
            "confidence": 0.95,
            "severity": "critical"
        }
    },
    
    "service_deployment": {
        "name": "Safe Service Deployment",
        "action": "deploy_service v1.2.3 to staging with 25% canary",
        "description": "Standard deployment with canary testing",
        "context": {
            "environment": "staging",
            "service": "api-gateway",
            "version": "v1.2.3",
            "canary_percentage": 25,
            "rollback_feasible": True,
            "rollback_time": "2 minutes"
        },
        "oss_result": {
            "risk_level": "Low",
            "confidence": 0.88,
            "recommendation": "✅ Looks safe - Can execute with monitoring",
            "policy_violations": 0,
            "can_execute": True,
            "execution_status": "APPROVED (Advisory)",
            "reason": "Meets all safety criteria and has rollback plan"
        },
        "enterprise_result": {
            "license_tier": "professional",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Professional license valid"},
                {"name": "confidence_threshold", "required": True, "passed": True, "message": "Confidence 0.88 ≥ 0.70"},
                {"name": "rollback_feasibility", "required": True, "passed": True, "message": "Rollback in 2 minutes"},
                {"name": "canary_safe", "required": True, "passed": True, "message": "25% canary within limits"},
                {"name": "environment_match", "required": True, "passed": True, "message": "Staging environment"}
            ],
            "gates_passed": 5,
            "total_gates": 5,
            "execution_authority": "GRANTED",
            "enforcement_type": "Autonomous Execution",
            "audit_trail": True,
            "auto_remediation": "Auto-deploy with monitoring",
            "value_prop": "Fully autonomous execution saves 15 minutes per deployment"
        },
        "visualization": {
            "risk_score": 0.12,
            "confidence": 0.88,
            "severity": "low"
        }
    },
    
    "config_change": {
        "name": "Configuration Change",
        "action": "UPDATE config SET timeout=30 WHERE service='payment'",
        "description": "Update payment service timeout configuration",
        "context": {
            "environment": "production",
            "service": "payment",
            "change_type": "configuration",
            "affected_services": ["payment", "checkout"],
            "validation_required": True
        },
        "oss_result": {
            "risk_level": "Medium",
            "confidence": 0.75,
            "recommendation": "⚠️ Review recommended - Medium risk to payment services",
            "policy_violations": 1,
            "can_execute": False,
            "execution_status": "REVIEW REQUIRED",
            "reason": "Production payment service changes require additional review"
        },
        "enterprise_result": {
            "license_tier": "starter",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Starter license valid"},
                {"name": "risk_assessment", "required": True, "passed": True, "message": "Risk score 0.25 ≤ 0.80"},
                {"name": "payment_service", "required": True, "passed": False, "message": "Payment service requires admin approval"},
                {"name": "admin_approval", "required": True, "passed": True, "message": "Admin approval received"},
                {"name": "change_window", "required": True, "passed": True, "message": "Within maintenance window"}
            ],
            "gates_passed": 4,
            "total_gates": 5,
            "execution_authority": "GRANTED",
            "enforcement_type": "Human-in-the-Loop Approval",
            "audit_trail": True,
            "auto_remediation": "Queued for execution after approval",
            "value_prop": "Human oversight with mechanical validation ensures safety"
        },
        "visualization": {
            "risk_score": 0.25,
            "confidence": 0.75,
            "severity": "medium"
        }
    },
    
    "user_permission_grant": {
        "name": "User Permission Grant",
        "action": "GRANT admin_role TO user@company.com",
        "description": "Grant administrative privileges to user",
        "context": {
            "environment": "production",
            "role": "admin_role",
            "user": "user@company.com",
            "justification": "New team member",
            "approver": "cto@company.com"
        },
        "oss_result": {
            "risk_level": "High",
            "confidence": 0.82,
            "recommendation": "❌ High risk - Administrative grants require multi-factor approval",
            "policy_violations": 2,
            "can_execute": False,
            "execution_status": "BLOCKED (Advisory)",
            "reason": "Admin role grants require additional security review"
        },
        "enterprise_result": {
            "license_tier": "enterprise",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Enterprise license valid"},
                {"name": "security_review", "required": True, "passed": True, "message": "Security team review completed"},
                {"name": "multi_factor_auth", "required": True, "passed": True, "message": "MFA verification passed"},
                {"name": "compliance_check", "required": True, "passed": True, "message": "SOX compliance validated"},
                {"name": "approval_chain", "required": True, "passed": True, "message": "CTO and Security Lead approved"}
            ],
            "gates_passed": 5,
            "total_gates": 5,
            "execution_authority": "GRANTED",
            "enforcement_type": "Compliance-Enforced Execution",
            "audit_trail": True,
            "auto_remediation": "Auto-provision with compliance logging",
            "value_prop": "Automates complex compliance requirements with full audit trail"
        },
        "visualization": {
            "risk_score": 0.68,
            "confidence": 0.82,
            "severity": "high"
        }
    },
    
    "sensitive_data_access": {
        "name": "Sensitive Data Access",
        "action": "SELECT * FROM pci_data WHERE card_number LIKE '4111%'",
        "description": "Access to PCI-sensitive payment card data",
        "context": {
            "environment": "production",
            "data_classification": "pci",
            "user_role": "analyst",
            "purpose": "fraud investigation",
            "masking_required": True
        },
        "oss_result": {
            "risk_level": "Critical",
            "confidence": 0.99,
            "recommendation": "🚨 CRITICAL RISK - PCI data access requires special authorization",
            "policy_violations": 3,
            "can_execute": False,
            "execution_status": "BLOCKED (Advisory)",
            "reason": "PCI data access requires Data Protection Officer approval"
        },
        "enterprise_result": {
            "license_tier": "enterprise",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Enterprise license valid"},
                {"name": "pci_compliance", "required": True, "passed": True, "message": "PCI DSS 4.0 compliant"},
                {"name": "data_masking", "required": True, "passed": True, "message": "Auto-masking enabled"},
                {"name": "dpo_approval", "required": True, "passed": True, "message": "Data Protection Officer approved"},
                {"name": "audit_logging", "required": True, "passed": True, "message": "Full query logging enabled"},
                {"name": "access_time_limit", "required": True, "passed": True, "message": "4-hour access window"}
            ],
            "gates_passed": 6,
            "total_gates": 6,
            "execution_authority": "GRANTED (WITH SAFEGUARDS)",
            "enforcement_type": "Compliance-Enforced with Safeguards",
            "audit_trail": True,
            "auto_remediation": "Auto-masking + time-limited access",
            "value_prop": "Enables necessary work while automatically enforcing compliance"
        },
        "visualization": {
            "risk_score": 0.99,
            "confidence": 0.99,
            "severity": "critical"
        }
    },
    
    "auto_scaling_adjustment": {
        "name": "Auto-Scaling Adjustment",
        "action": "scale deployment frontend from 10 to 50 pods",
        "description": "Increase frontend service capacity",
        "context": {
            "environment": "production",
            "service": "frontend",
            "current_pods": 10,
            "target_pods": 50,
            "reason": "Black Friday traffic spike",
            "budget_impact": "$1200/day"
        },
        "oss_result": {
            "risk_level": "Low",
            "confidence": 0.92,
            "recommendation": "✅ Safe - Standard scaling operation",
            "policy_violations": 0,
            "can_execute": True,
            "execution_status": "APPROVED (Advisory)",
            "reason": "Within normal operational parameters"
        },
        "enterprise_result": {
            "license_tier": "professional",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Professional license valid"},
                {"name": "budget_check", "required": True, "passed": True, "message": "Within monthly budget"},
                {"name": "capacity_planning", "required": True, "passed": True, "message": "Matches capacity plan"},
                {"name": "auto_scale", "required": True, "passed": True, "message": "Auto-scaling group configured"},
                {"name": "monitoring", "required": True, "passed": True, "message": "CloudWatch alarms active"}
            ],
            "gates_passed": 5,
            "total_gates": 5,
            "execution_authority": "GRANTED",
            "enforcement_type": "Autonomous Execution",
            "audit_trail": True,
            "auto_remediation": "Auto-scale with cost optimization",
            "value_prop": "Fully autonomous scaling with cost controls"
        },
        "visualization": {
            "risk_score": 0.08,
            "confidence": 0.92,
            "severity": "low"
        }
    },
    
    "emergency_rollback": {
        "name": "Emergency Rollback",
        "action": "rollback_service payment to v1.1.0 immediately",
        "description": "Emergency rollback due to critical bug",
        "context": {
            "environment": "production",
            "service": "payment",
            "from_version": "v1.2.0",
            "to_version": "v1.1.0",
            "severity": "critical",
            "incident_id": "INC-2024-789",
            "approved_by": "oncall_engineer"
        },
        "oss_result": {
            "risk_level": "Medium",
            "confidence": 0.78,
            "recommendation": "⚠️ Proceed with caution - Rollback may affect transactions",
            "policy_violations": 0,
            "can_execute": True,
            "execution_status": "APPROVED (Advisory)",
            "reason": "Emergency override for critical incident"
        },
        "enterprise_result": {
            "license_tier": "enterprise",
            "gates": [
                {"name": "license_validation", "required": True, "passed": True, "message": "Enterprise license valid"},
                {"name": "emergency_override", "required": True, "passed": True, "message": "Emergency mode activated"},
                {"name": "incident_linked", "required": True, "passed": True, "message": "Linked to INC-2024-789"},
                {"name": "rollback_safe", "required": True, "passed": True, "message": "Rollback path verified"},
                {"name": "communication_sent", "required": True, "passed": True, "message": "Stakeholders notified"},
                {"name": "post_mortem_required", "required": True, "passed": True, "message": "Post-mortem queued"}
            ],
            "gates_passed": 6,
            "total_gates": 6,
            "execution_authority": "GRANTED",
            "enforcement_type": "Emergency Protocol Execution",
            "audit_trail": True,
            "auto_remediation": "Auto-rollback with incident linking",
            "value_prop": "Structured emergency response with full audit and post-mortem automation"
        },
        "visualization": {
            "risk_score": 0.22,
            "confidence": 0.78,
            "severity": "medium"
        }
    }
}

# Gate definitions for visualization
GATE_DEFINITIONS = {
    "license_validation": {
        "description": "Validate enterprise license is active and appropriate tier",
        "weight": 0.3,
        "required": True,
        "enterprise_only": True
    },
    "confidence_threshold": {
        "description": "Confidence score must meet minimum threshold",
        "weight": 0.25,
        "required": True,
        "threshold": 0.7
    },
    "risk_assessment": {
        "description": "Risk score must be below maximum threshold",
        "weight": 0.25,
        "required": True,
        "threshold": 0.8
    },
    "rollback_feasibility": {
        "description": "Rollback plan must exist and be feasible",
        "weight": 0.1,
        "required": False,
        "enterprise_only": False
    },
    "admin_approval": {
        "description": "Human approval required for certain actions",
        "weight": 0.1,
        "required": False,
        "enterprise_only": True,
        "tiers": ["starter"]
    },
    "compliance_check": {
        "description": "Compliance with regulations (GDPR, PCI, SOX, etc.)",
        "weight": 0.1,
        "required": False,
        "enterprise_only": True,
        "tiers": ["enterprise"]
    },
    "budget_check": {
        "description": "Check against budget limits and forecasts",
        "weight": 0.05,
        "required": False,
        "enterprise_only": True
    }
}

# License tier comparisons
LICENSE_TIERS = {
    "trial": {
        "name": "Trial",
        "price": 0,
        "enforcement": "advisory",
        "max_agents": 3,
        "gates_available": ["confidence_threshold", "risk_assessment"],
        "limitations": ["No mechanical enforcement", "14-day limit", "Community support"],
        "best_for": "Evaluation and testing"
    },
    "starter": {
        "name": "Starter",
        "price": 2000,
        "enforcement": "human_approval",
        "max_agents": 10,
        "gates_available": ["license_validation", "confidence_threshold", "risk_assessment", "admin_approval"],
        "features": ["Human-in-the-loop gates", "Basic audit trail", "Email support"],
        "best_for": "Small teams with human oversight"
    },
    "professional": {
        "name": "Professional",
        "price": 5000,
        "enforcement": "autonomous",
        "max_agents": 50,
        "gates_available": ["license_validation", "confidence_threshold", "risk_assessment", "rollback_feasibility", "budget_check"],
        "features": ["Autonomous execution", "Advanced audit", "Priority support", "SLA 99.5%"],
        "best_for": "Mid-size companies wanting automation"
    },
    "enterprise": {
        "name": "Enterprise",
        "price": 15000,
        "enforcement": "full_mechanical",
        "max_agents": 1000,
        "gates_available": ["license_validation", "confidence_threshold", "risk_assessment", "rollback_feasibility", "compliance_check", "budget_check", "custom_gates"],
        "features": ["Full mechanical enforcement", "Compliance automation", "Custom gates", "24/7 support", "SLA 99.9%", "Differential privacy audit"],
        "best_for": "Large enterprises with compliance needs"
    }
}

# Value proposition data
VALUE_PROPOSITIONS = {
    "risk_reduction": {
        "oss": "Manual risk assessment",
        "starter": "Human-validated decisions",
        "professional": "Automated risk gates",
        "enterprise": "Mechanical enforcement",
        "improvement": "92% reduction in operational risk"
    },
    "decision_speed": {
        "oss": "Minutes to hours",
        "starter": "Minutes with human",
        "professional": "Seconds (autonomous)",
        "enterprise": "Milliseconds (mechanical)",
        "improvement": "100x faster decisions"
    },
    "false_positives": {
        "oss": "High (conservative)",
        "starter": "Medium (human calibrated)",
        "professional": "Low (ML-optimized)",
        "enterprise": "Minimal (continuously tuned)",
        "improvement": "85% reduction in false positives"
    },
    "operational_cost": {
        "oss": "High (manual review)",
        "starter": "Medium (partial automation)",
        "professional": "Low (mostly automated)",
        "enterprise": "Minimal (fully automated)",
        "improvement": "75% reduction in OpEx"
    }
}

def get_scenario_by_name(name: str) -> Dict:
    """Get scenario by name"""
    return DEMO_SCENARIOS.get(name, {})

def get_all_scenario_names() -> List[str]:
    """Get all scenario names"""
    return list(DEMO_SCENARIOS.keys())

def get_scenario_summary() -> List[Dict]:
    """Get summary of all scenarios"""
    summary = []
    for key, scenario in DEMO_SCENARIOS.items():
        summary.append({
            "id": key,
            "name": scenario["name"],
            "action": scenario["action"],
            "risk_level": scenario["oss_result"]["risk_level"],
            "oss_can_execute": scenario["oss_result"]["can_execute"],
            "enterprise_gates_passed": scenario["enterprise_result"]["gates_passed"],
            "enterprise_total_gates": scenario["enterprise_result"]["total_gates"]
        })
    return summary

def generate_upgrade_path(current_tier: str, target_tier: str) -> Dict:
    """Generate upgrade path between tiers"""
    current = LICENSE_TIERS.get(current_tier, LICENSE_TIERS["trial"])
    target = LICENSE_TIERS.get(target_tier, LICENSE_TIERS["enterprise"])
    
    new_gates = [gate for gate in target["gates_available"] if gate not in current["gates_available"]]
    new_features = [feat for feat in target.get("features", []) if feat not in current.get("features", [])]
    
    return {
        "from": current["name"],
        "to": target["name"],
        "price_increase": target["price"] - current["price"],
        "new_gates": new_gates,
        "new_features": new_features,
        "enforcement_improvement": f"{current['enforcement']}{target['enforcement']}",
        "agent_limit_increase": target["max_agents"] - current["max_agents"],
        "roi_calculation": _calculate_roi(current["price"], target["price"])
    }

def _calculate_roi(current_price: int, target_price: int) -> Dict:
    """Calculate ROI for upgrade"""
    price_diff = target_price - current_price
    
    # Simplified ROI calculation
    time_savings = 15 * 20 * 12  # 15 min saved per decision, 20 decisions/day, 12 months
    risk_reduction = 0.92 * 100000  # 92% reduction in $100k average incident cost
    false_positive_savings = 0.85 * 50 * 200  # 85% reduction in 50 false positives/month at $200 each
    
    total_savings = time_savings + risk_reduction + false_positive_savings
    roi_months = (price_diff * 12) / total_savings if total_savings > 0 else 0
    
    return {
        "annual_price_difference": price_diff * 12,
        "estimated_annual_savings": total_savings,
        "roi_months": max(1, roi_months),
        "breakeven": roi_months <= 12
    }