"""Programme-level quantitative goals and thresholds — Tata Steel Invictus Programme.

Single source of truth for all numeric targets, baselines, and alert thresholds.
Edit this file to update goals without touching agent prompt logic.
Both the rt_agent and tatasteel agent pick this up at import time via their
respective prompt-builder functions.
"""
from __future__ import annotations

from datetime import date

PROGRAMME_CONFIG: dict = {
    # ── Investment ────────────────────────────────────────────────────────────
    "investment": {
        # "overall_gbp": 1_250_000_000,   # £1.25B — total programme investment
        "tsuk_gbp":      750_000_000,   # £750M  — Tata Steel UK contribution
        "uk_govt_gbp":   500_000_000,   # £500M  — UK Government contribution
        "description": "Green Steel production using Electric Arc Furnace (EAF) model",
    },

    # ── Programme schedule ────────────────────────────────────────────────────
    "schedule": {
        "start_date": date(2024, 8, 20),
        "end_date":   date(2029, 1, 31),
    },

    # ── Alert thresholds ──────────────────────────────────────────────────────
    "thresholds": {
        "contractor_budget_deviation_pct": 10,  # flag if uplift > 10% of initial contract value
        "variance_quick_approve_pct": 5,        # variance below this % = quick-approve candidate
    },
}


def make_programme_config_prompt() -> str:
    """Return a compact numbers-only block injected into both agent prompts."""
    inv = PROGRAMME_CONFIG["investment"]
    sch = PROGRAMME_CONFIG["schedule"]
    thr = PROGRAMME_CONFIG["thresholds"]

    return f"""\
━━━ PROGRAMME GOALS (reference numbers) ━━━
TSUK allotted budget : £{inv['tsuk_gbp'] / 1e6:.0f}M
  ↳ This is the TSUK-approved funding envelope for the programme — use it for budget coverage and health questions
    (e.g. "are we within budget?", "how much budget remains?", "contracted scope vs allotted budget").
  ↳ Do NOT use this as the denominator for variance % — see BASELINE rule below.

Programme baseline : SUM(initial_contract_value) from ts4_contracts
  ↳ This is the total awarded contract value at the time of award — the denominator for ALL variance % calculations.
  ↳ Variance % = SUM(accepted change_to_prices) / SUM(initial_contract_value).
  ↳ Always compute this from the database; do not substitute the allotted budget figure.

Budget coverage rule : when the question concerns budget health, compare
  SUM(initial_contract_value) + SUM(accepted change_to_prices) against the TSUK allotted budget of £{inv['tsuk_gbp'] / 1e6:.0f}M.
UK Government co-investment : £{inv['uk_govt_gbp'] / 1e6:.0f}M  (separate funding stream, not in database)

Programme start  : {sch['start_date'].strftime('%d %b %Y')}
Programme end    : {sch['end_date'].strftime('%d %b %Y')}
Budget deviation alert threshold (per contractor) : {thr['contractor_budget_deviation_pct']}%
Variance quick-approve threshold (per contractor) : {thr['variance_quick_approve_pct']}%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"""
