# =============================================================================
# B3: Owner Routing Matrix
# Universal Review Taxonomy v5.1
# =============================================================================
#
# Maps URT codes to responsible teams/individuals for ticket routing.
# Resolution order: subcode_overrides > category_overrides > domain_defaults
#
# Status: Production Ready
# Release Date: 2026-01-23
# Prerequisite: B1-urt-codes.yaml (Code Registry)
# =============================================================================

version: "5.1"
status: "production"
release_date: "2026-01-23"

# =============================================================================
# ROUTING RULES
# =============================================================================

routing_rules:

  # ---------------------------------------------------------------------------
  # DOMAIN DEFAULTS
  # Baseline routing for each of the 7 experience domains
  # ---------------------------------------------------------------------------
  domain_defaults:
    O:
      team: "product"
      escalation: "product_director"
      description: "Core product/service delivery issues"
      typical_response: "Product review, quality control audit"

    P:
      team: "hr"
      escalation: "hr_director"
      description: "Personnel behavior and performance issues"
      typical_response: "Staff coaching, training intervention"

    J:
      team: "operations"
      escalation: "operations_director"
      description: "Process, timing, and operational flow issues"
      typical_response: "Process improvement, workflow optimization"

    E:
      team: "facilities"
      escalation: "facilities_director"
      description: "Physical and digital environment issues"
      typical_response: "Maintenance dispatch, IT ticket"

    A:
      team: "compliance"
      escalation: "compliance_director"
      description: "Availability, accessibility, and inclusivity issues"
      typical_response: "Accessibility audit, policy review"

    V:
      team: "finance"
      escalation: "finance_director"
      description: "Pricing, value, and cost-related issues"
      typical_response: "Pricing review, refund authorization"

    R:
      team: "leadership"
      escalation: "ceo"
      description: "Trust, relationship, and organizational integrity issues"
      typical_response: "Executive review, strategic response"

  # ---------------------------------------------------------------------------
  # CATEGORY-LEVEL OVERRIDES
  # More specific routing for category-level patterns
  # ---------------------------------------------------------------------------
  category_overrides:
    # Offering categories
    O1:
      team: "product_engineering"
      escalation: "engineering_lead"
      notes: "Function issues often require technical investigation"
    O2:
      team: "quality_control"
      escalation: "qa_manager"
      notes: "Quality issues route to QC team"
    O3:
      team: "fulfillment"
      escalation: "fulfillment_manager"
      notes: "Completeness issues often involve shipping/delivery"
    O4:
      team: "product"
      escalation: "product_manager"
      notes: "Fit issues inform product development"

    # People categories
    P1:
      team: "hr_training"
      escalation: "hr_director"
      notes: "Attitude issues require coaching/culture work"
    P2:
      team: "training"
      escalation: "training_manager"
      notes: "Competence issues indicate training gaps"
    P3:
      team: "operations"
      escalation: "operations_manager"
      notes: "Responsiveness often tied to operational capacity"
    P4:
      team: "training"
      escalation: "training_manager"
      notes: "Communication skills are trainable"

    # Journey categories
    J1:
      team: "operations"
      escalation: "operations_manager"
      notes: "Timing issues require process optimization"
    J2:
      team: "process_improvement"
      escalation: "operations_director"
      notes: "Ease/friction issues benefit from process redesign"
    J3:
      team: "operations"
      escalation: "operations_manager"
      notes: "Reliability issues need root cause analysis"
    J4:
      team: "customer_service"
      escalation: "cx_director"
      notes: "Resolution issues are CX team primary focus"

    # Environment categories
    E1:
      team: "facilities"
      escalation: "facilities_manager"
      notes: "Physical space issues"
    E2:
      team: "it"
      escalation: "cto"
      notes: "Digital space issues route to IT/Engineering"
    E3:
      team: "facilities"
      escalation: "facilities_manager"
      notes: "Ambiance is facility management concern"
    E4:
      team: "safety"
      escalation: "safety_officer"
      notes: "Safety issues require immediate attention"

    # Access categories
    A1:
      team: "operations"
      escalation: "operations_director"
      notes: "Availability is operational capacity"
    A2:
      team: "accessibility"
      escalation: "compliance_director"
      notes: "Accessibility requires specialized audit"
    A3:
      team: "dei"
      escalation: "dei_director"
      notes: "Inclusivity issues route to DEI team"
    A4:
      team: "operations"
      escalation: "operations_manager"
      notes: "Convenience is operational concern"

    # Value categories
    V1:
      team: "pricing"
      escalation: "finance_director"
      notes: "Price issues need pricing team review"
    V2:
      team: "legal"
      escalation: "general_counsel"
      notes: "Transparency issues may have legal implications"
    V3:
      team: "cx"
      escalation: "cx_director"
      notes: "Effort issues are customer experience concern"
    V4:
      team: "leadership"
      escalation: "ceo"
      notes: "Worth/satisfaction is strategic concern"

    # Relationship categories
    R1:
      team: "leadership"
      escalation: "ceo"
      notes: "Integrity issues are executive concern"
    R2:
      team: "operations"
      escalation: "coo"
      notes: "Dependability reflects operational excellence"
    R3:
      team: "cx"
      escalation: "cx_director"
      notes: "Recovery is core CX competency"
    R4:
      team: "marketing"
      escalation: "cmo"
      notes: "Loyalty is marketing/retention concern"

  # ---------------------------------------------------------------------------
  # SUBCODE-LEVEL OVERRIDES
  # Most specific routing for individual subcodes
  # ---------------------------------------------------------------------------
  subcode_overrides:
    # Critical safety subcodes - always escalate
    E4.01:
      team: "safety"
      escalation: "safety_officer"
      auto_escalate: true
      sla_override_hours: 1
      notes: "Physical safety is always critical"
    E4.02:
      team: "safety"
      escalation: "safety_officer"
      auto_escalate: true
      sla_override_hours: 2
      notes: "Health/hygiene requires immediate attention"
    E4.05:
      team: "safety"
      escalation: "safety_officer"
      auto_escalate: true
      sla_override_hours: 1
      notes: "Emergency readiness is critical"

    # Digital/IT specific subcodes
    E2.01:
      team: "ux_design"
      escalation: "ux_lead"
      notes: "Interface design issues route to UX"
    E2.02:
      team: "engineering"
      escalation: "engineering_lead"
      notes: "Digital functionality is engineering concern"
    E2.03:
      team: "devops"
      escalation: "cto"
      notes: "Performance issues may be infrastructure"
    E2.04:
      team: "ux_design"
      escalation: "ux_lead"
      notes: "Navigation is UX concern"
    E2.05:
      team: "mobile_engineering"
      escalation: "mobile_lead"
      notes: "Mobile experience routes to mobile team"

    # Discrimination - always escalate
    A3.05:
      team: "hr"
      escalation: "hr_director"
      auto_escalate: true
      sla_override_hours: 4
      co_owner: "legal"
      notes: "Equal treatment issues require HR and legal"

    # Accessibility compliance
    A2.01:
      team: "facilities"
      escalation: "compliance_director"
      co_owner: "accessibility"
      notes: "Physical accessibility may require ADA compliance"
    A2.02:
      team: "accessibility"
      escalation: "compliance_director"
      notes: "Visual accessibility is WCAG concern"
    A2.03:
      team: "accessibility"
      escalation: "compliance_director"
      notes: "Hearing accessibility is compliance concern"
    A2.04:
      team: "ux_design"
      escalation: "compliance_director"
      notes: "Cognitive accessibility affects design"
    A2.05:
      team: "engineering"
      escalation: "compliance_director"
      notes: "Digital accessibility requires eng work"

    # Security breaches
    E4.03:
      team: "security"
      escalation: "cso"
      auto_escalate: true
      sla_override_hours: 1
      notes: "Security incidents require immediate response"

    # Ethics/integrity - executive level
    R1.04:
      team: "leadership"
      escalation: "ceo"
      auto_escalate: true
      sla_override_hours: 4
      co_owner: "legal"
      notes: "Ethics issues are executive priority"

    # Billing/refund specific
    V1.04:
      team: "billing"
      escalation: "finance_director"
      notes: "Hidden costs need billing team review"
    V2.02:
      team: "billing"
      escalation: "finance_director"
      co_owner: "legal"
      notes: "Fee disclosure may have compliance implications"
    V2.04:
      team: "legal"
      escalation: "general_counsel"
      notes: "Terms fairness is legal concern"

    # Staff-specific issues
    P1.02:
      team: "hr"
      escalation: "hr_director"
      notes: "Respect issues need HR intervention"
    P2.04:
      team: "hr"
      escalation: "hr_director"
      notes: "Professionalism is HR concern"

  # ---------------------------------------------------------------------------
  # INTENSITY-BASED ESCALATION
  # SLA and escalation rules by sentiment intensity
  # ---------------------------------------------------------------------------
  intensity_escalation:
    I3:
      auto_escalate: true
      sla_hours: 4
      notification_level: "director"
      priority: "critical"
      description: "Strong negative - requires immediate attention"
    I2:
      auto_escalate: false
      sla_hours: 24
      notification_level: "manager"
      priority: "high"
      description: "Moderate negative - standard priority"
    I1:
      auto_escalate: false
      sla_hours: 72
      notification_level: "team"
      priority: "normal"
      description: "Mild negative - normal queue"

  # ---------------------------------------------------------------------------
  # VALENCE-BASED ROUTING MODIFIERS
  # Different handling for positive vs negative feedback
  # ---------------------------------------------------------------------------
  valence_routing:
    "V+":
      action: "acknowledge"
      sla_hours: 48
      team_modifier: null
      notes: "Positive feedback routes to recognition workflow"
    "V-":
      action: "resolve"
      sla_hours: null  # Uses intensity-based SLA
      team_modifier: null
      notes: "Negative feedback uses standard routing"
    "V0":
      action: "log"
      sla_hours: null  # No SLA for neutral
      team_modifier: null
      notes: "Neutral observations logged for analytics"
    "V+-":
      action: "resolve"
      sla_hours: null
      team_modifier: null
      notes: "Mixed feedback prioritizes negative element"

  # ---------------------------------------------------------------------------
  # CAUSAL CODE ROUTING
  # Routes for root cause analysis codes
  # ---------------------------------------------------------------------------
  causal_routing:
    # Conditions layer
    "CD-S":
      team: "hr"
      escalation: "hr_director"
      notes: "Staff state issues - HR/wellness concern"
    "CD-T":
      team: "operations"
      escalation: "operations_manager"
      notes: "Team dynamics - operational leadership"
    "CD-E":
      team: "facilities"
      escalation: "facilities_manager"
      notes: "Equipment issues - facilities/IT"
    "CD-F":
      team: "facilities"
      escalation: "facilities_director"
      notes: "Facility issues - maintenance"
    "CD-O":
      team: "operations"
      escalation: "operations_director"
      notes: "Operational conditions - ops leadership"

    # Management layer
    "MG-P":
      team: "operations"
      escalation: "operations_director"
      notes: "Planning failures - ops management"
    "MG-T":
      team: "training"
      escalation: "hr_director"
      notes: "Training gaps - L&D team"
    "MG-O":
      team: "operations"
      escalation: "operations_director"
      notes: "Oversight failures - management review"
    "MG-R":
      team: "procurement"
      escalation: "finance_director"
      notes: "Resource issues - procurement/finance"
    "MG-C":
      team: "leadership"
      escalation: "coo"
      notes: "Communication failures - leadership"

    # Systemic layer
    "SY-R":
      team: "leadership"
      escalation: "cfo"
      notes: "Resource decisions - executive finance"
    "SY-P":
      team: "leadership"
      escalation: "coo"
      notes: "Policy issues - executive operations"
    "SY-C":
      team: "leadership"
      escalation: "ceo"
      notes: "Culture issues - executive leadership"
    "SY-S":
      team: "leadership"
      escalation: "coo"
      notes: "Standards issues - executive ops"
    "SY-H":
      team: "hr"
      escalation: "chro"
      notes: "Human capital - HR leadership"
    "SY-X":
      team: "leadership"
      escalation: "ceo"
      notes: "External factors - executive strategy"

# =============================================================================
# SCHEDULING AND ON-CALL
# =============================================================================

scheduling:
  business_hours:
    start: "09:00"
    end: "17:00"
    timezone: "UTC"
    days: ["monday", "tuesday", "wednesday", "thursday", "friday"]

  on_call_teams:
    - team: "support"
      coverage: "24/7"
      handles:
        - "I3"  # Critical intensity
        - "E4"  # Safety issues
        - "E4.03"  # Security
    - team: "operations"
      coverage: "extended"
      hours: "06:00-22:00"
      handles:
        - "J4"  # Resolution issues
        - "J1"  # Timing issues

  holiday_coverage:
    minimum_teams: ["support"]
    escalation_delay_multiplier: 1.5

# =============================================================================
# MULTI-CODE SPAN ROUTING
# =============================================================================

multi_code_rules:
  # When a span has multiple codes, determine primary owner
  priority_resolution:
    method: "highest_priority_team"
    tiebreaker: "primary_code_wins"

  # Domain priority order (for conflicts)
  domain_priority:
    1: "E4"   # Safety always first
    2: "R1"   # Integrity/ethics
    3: "A3"   # Discrimination/inclusivity
    4: "P"    # People issues
    5: "V"    # Value issues
    6: "J"    # Journey issues
    7: "O"    # Offering issues
    8: "E"    # Environment (non-safety)
    9: "A"    # Access (non-discrimination)
    10: "R"   # Relationship (non-integrity)

  # Secondary code handling
  secondary_code_behavior:
    notify_co_owners: true
    add_to_ticket_tags: true
    require_sign_off: false

# =============================================================================
# CROSS-FUNCTIONAL ROUTING PATTERNS
# =============================================================================

cross_functional:
  # Patterns that always involve multiple teams
  patterns:
    security_breach:
      trigger_codes: ["E4.03", "R1.04"]
      teams: ["security", "legal", "leadership"]
      escalation: "ceo"
      sla_hours: 1

    discrimination_complaint:
      trigger_codes: ["A3.05", "P1.02"]
      teams: ["hr", "legal", "dei"]
      escalation: "hr_director"
      sla_hours: 4

    billing_dispute:
      trigger_codes: ["V1.04", "V2.02", "V2.04"]
      teams: ["billing", "legal", "cx"]
      escalation: "finance_director"
      sla_hours: 24

    product_failure:
      trigger_codes: ["O1.01", "O1.04"]
      conditions:
        intensity: "I3"
      teams: ["product_engineering", "qa", "cx"]
      escalation: "product_director"
      sla_hours: 4

    systemic_issue:
      trigger_codes: ["SY-C", "SY-P", "SY-R"]
      teams: ["leadership", "operations"]
      escalation: "ceo"
      sla_hours: 24

# =============================================================================
# TEAM DEFINITIONS
# =============================================================================

teams:
  product:
    name: "Product Team"
    email: "product@example.com"
    slack: "#product-team"
    manager: "product_director"

  hr:
    name: "Human Resources"
    email: "hr@example.com"
    slack: "#hr-team"
    manager: "hr_director"

  operations:
    name: "Operations"
    email: "ops@example.com"
    slack: "#operations"
    manager: "operations_director"

  facilities:
    name: "Facilities Management"
    email: "facilities@example.com"
    slack: "#facilities"
    manager: "facilities_director"

  it:
    name: "IT/Engineering"
    email: "it@example.com"
    slack: "#engineering"
    manager: "cto"

  compliance:
    name: "Compliance"
    email: "compliance@example.com"
    slack: "#compliance"
    manager: "compliance_director"

  finance:
    name: "Finance"
    email: "finance@example.com"
    slack: "#finance"
    manager: "finance_director"

  leadership:
    name: "Executive Leadership"
    email: "leadership@example.com"
    slack: "#leadership"
    manager: "ceo"

  cx:
    name: "Customer Experience"
    email: "cx@example.com"
    slack: "#customer-experience"
    manager: "cx_director"

  safety:
    name: "Safety & Security"
    email: "safety@example.com"
    slack: "#safety"
    manager: "safety_officer"

  legal:
    name: "Legal"
    email: "legal@example.com"
    slack: "#legal"
    manager: "general_counsel"

  training:
    name: "Learning & Development"
    email: "training@example.com"
    slack: "#training"
    manager: "training_manager"

  accessibility:
    name: "Accessibility"
    email: "accessibility@example.com"
    slack: "#accessibility"
    manager: "accessibility_lead"

  dei:
    name: "Diversity, Equity & Inclusion"
    email: "dei@example.com"
    slack: "#dei"
    manager: "dei_director"

# =============================================================================
# ESCALATION HIERARCHY
# =============================================================================

escalation_hierarchy:
  levels:
    1: "team_lead"
    2: "manager"
    3: "director"
    4: "vp"
    5: "c_suite"

  auto_escalation_rules:
    sla_breach:
      after_hours: 2
      escalate_to: "+1 level"

    repeated_issue:
      threshold: 3
      window_days: 30
      escalate_to: "+1 level"

    vip_customer:
      always_notify: "director"
      sla_multiplier: 0.5

# =============================================================================
# SLA DEFINITIONS
# =============================================================================

sla:
  response_times:
    critical:
      initial_response_hours: 1
      resolution_hours: 4
      update_frequency_hours: 1
    high:
      initial_response_hours: 4
      resolution_hours: 24
      update_frequency_hours: 4
    normal:
      initial_response_hours: 24
      resolution_hours: 72
      update_frequency_hours: 24
    low:
      initial_response_hours: 48
      resolution_hours: 168  # 1 week
      update_frequency_hours: 48

  breach_actions:
    warning:
      at_percent: 75
      action: "notify_manager"
    critical:
      at_percent: 100
      action: "escalate_and_notify_director"
    overdue:
      at_percent: 150
      action: "escalate_to_vp"
