#!/usr/bin/env python3
"""Fair lending analysis: Causal decomposition of protected-attribute effects.

Demonstrates:
1. Decomposing total effect into direct and indirect paths.
2. Identifying legitimate vs. concerning causal pathways.
3. Assessing disparate impact through causal reasoning.
"""

from orxaq.orchestration.integration import OrxaqEngine

engine = OrxaqEngine()
engine.load_credit_ontology()

# --- Fair lending analysis for age ---
print("=== Fair Lending: Age ===")
decomp = engine.fairness_audit(protected="age")
print(f"Protected variable: {decomp.protected_var}")
print(f"Outcome variable: {decomp.outcome_var}")
print(f"Total effect: {decomp.total_effect:.6f}")
print(f"Direct effect: {decomp.direct_effect:.6f}")
print("\nIndirect effects (via mediators):")
for mediator, effect in sorted(decomp.indirect_effects.items()):
    print(f"  via {mediator}: {effect:.6f}")
print(f"\nLegitimate paths ({len(decomp.legitimate_paths)}):")
for path in decomp.legitimate_paths:
    print(f"  {' -> '.join(path)}")
print(f"\nConcerning paths ({len(decomp.concerning_paths)}):")
for path in decomp.concerning_paths:
    print(f"  {' -> '.join(path)}")
