"""
ACT 1: THE HOOK - The Trap (Correlation ≠ Causation)
Dataset: tech_hiring_macro_trends.csv
Purpose: Show how the SAME data tells different stories depending on what you plot.
"""

import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots

# ── Load Data ──────────────────────────────────────────────
df = pd.read_csv("data/tech_hiring_macro_trends.csv", parse_dates=["Date"])

# ══════════════════════════════════════════════════════════════
# CHART 1: THE TRAP  – "AI is killing jobs"
# We plot Dev Jobs vs ChatGPT Traffic and let the viewer
# draw the WRONG conclusion: that ChatGPT caused the decline.
# ══════════════════════════════════════════════════════════════

fig_trap = make_subplots(specs=[[{"secondary_y": True}]])

fig_trap.add_trace(
    go.Scatter(
        x=df["Date"], y=df["Dev_Jobs"],
        name="Dev Job Postings (Index)",
        line=dict(color="#ef4444", width=3),
        mode="lines"
    ),
    secondary_y=False,
)

fig_trap.add_trace(
    go.Scatter(
        x=df["Date"], y=df["ChatGPT_Traffic"],
        name="ChatGPT Search Interest",
        line=dict(color="#22c55e", width=3, dash="dash"),
        mode="lines"
    ),
    secondary_y=True,
)

fig_trap.update_layout(
    title="🚩 The Trap: Did AI Kill the Entry-Level Job?",
    title_font_size=18,
    template="plotly_dark",
    paper_bgcolor="#0f172a",
    plot_bgcolor="#0f172a",
    legend=dict(orientation="h", y=-0.15),
    hovermode="x unified",
)
fig_trap.update_yaxes(title_text="Dev Job Postings (Index)", secondary_y=False)
fig_trap.update_yaxes(title_text="ChatGPT Search Interest", secondary_y=True)

fig_trap.show()

# ══════════════════════════════════════════════════════════════
# CHART 2: THE TRUTH  – "Interest Rates drove the downturn"
# Now we plot Dev Jobs vs Federal Interest Rate and the
# real economic driver becomes clear.
# ══════════════════════════════════════════════════════════════

fig_truth = make_subplots(specs=[[{"secondary_y": True}]])

fig_truth.add_trace(
    go.Scatter(
        x=df["Date"], y=df["Dev_Jobs"],
        name="Dev Job Postings (Index)",
        line=dict(color="#ef4444", width=3),
        mode="lines"
    ),
    secondary_y=False,
)

fig_truth.add_trace(
    go.Scatter(
        x=df["Date"], y=df["Fed_Interest"],
        name="Federal Interest Rate (%)",
        line=dict(color="#3b82f6", width=3, dash="dot"),
        mode="lines"
    ),
    secondary_y=True,
)

fig_truth.update_layout(
    title="✅ The Truth: Interest Rates Drove the Tech Hiring Freeze",
    title_font_size=18,
    template="plotly_dark",
    paper_bgcolor="#0f172a",
    plot_bgcolor="#0f172a",
    legend=dict(orientation="h", y=-0.15),
    hovermode="x unified",
)
fig_truth.update_yaxes(title_text="Dev Job Postings (Index)", secondary_y=False)
fig_truth.update_yaxes(title_text="Fed Interest Rate (%)", secondary_y=True)

fig_truth.show()

# ══════════════════════════════════════════════════════════════
# CHART 3: THE FULL PICTURE (Advanced)
# All four variables together for the complete narrative.
# ══════════════════════════════════════════════════════════════

fig_full = make_subplots(specs=[[{"secondary_y": True}]])

fig_full.add_trace(
    go.Scatter(x=df["Date"], y=df["Dev_Jobs"], name="Dev Jobs",
               line=dict(color="#ef4444", width=3)),
    secondary_y=False)

fig_full.add_trace(
    go.Scatter(x=df["Date"], y=df["AI_Jobs"], name="AI Jobs",
               line=dict(color="#a855f7", width=2)),
    secondary_y=False)

fig_full.add_trace(
    go.Scatter(x=df["Date"], y=df["ChatGPT_Traffic"], name="ChatGPT Interest",
               line=dict(color="#22c55e", width=2, dash="dash")),
    secondary_y=True)

fig_full.add_trace(
    go.Scatter(x=df["Date"], y=df["Fed_Interest"] * 20, name="Fed Rate (×20)",
               line=dict(color="#3b82f6", width=2, dash="dot")),
    secondary_y=True)

fig_full.update_layout(
    title="The Complete Picture: Dev Jobs, AI Jobs, ChatGPT & Interest Rates",
    template="plotly_dark",
    paper_bgcolor="#0f172a",
    plot_bgcolor="#0f172a",
    legend=dict(orientation="h", y=-0.15),
    hovermode="x unified",
)

fig_full.show()
