#!/usr/bin/env python3
"""Generate Roberto Aguirre CV for Anthropic Fellows Program — Economics & Policy track."""

from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
from reportlab.lib.colors import HexColor
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, HRFlowable
)
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.enums import TA_RIGHT, TA_JUSTIFY

OUTPUT = "/home/clawd/playgrounds/miles/cv-roberto-anthropic.pdf"

C_BLACK = HexColor("#0d0d0d")
C_MID   = HexColor("#444444")
C_LIGHT = HexColor("#666666")
C_FAINT = HexColor("#cccccc")
C_BODY  = HexColor("#333333")
C_GREY  = HexColor("#555555")

def S(name, **kw):
    return ParagraphStyle(name, **kw)

NAME     = S("name", fontName="Times-Bold",         fontSize=17, leading=21, textColor=C_BLACK, spaceAfter=1)
TITLEL   = S("tl",   fontName="Times-Roman",        fontSize=8.5, leading=11, textColor=C_MID,  spaceAfter=2)
CONTACT  = S("ct",   fontName="Helvetica",           fontSize=7.2, leading=10, textColor=C_GREY)
SECTITLE = S("st",   fontName="Helvetica-Bold",      fontSize=6.8, leading=9,  textColor=C_BLACK, spaceBefore=1, spaceAfter=2)
COMPANY  = S("co",   fontName="Helvetica-Bold",      fontSize=8,   leading=10, textColor=C_BLACK)
PERIOD   = S("per",  fontName="Helvetica",           fontSize=7.4, leading=10, textColor=C_LIGHT, alignment=TA_RIGHT)
ROLE     = S("ro",   fontName="Helvetica-Oblique",   fontSize=7.5, leading=9,  textColor=C_MID,  spaceAfter=1)
BODY     = S("bo",   fontName="Helvetica",           fontSize=7.4, leading=10.5,textColor=C_BODY, spaceAfter=4, alignment=TA_JUSTIFY)
SUMMARY  = S("su",   fontName="Times-Roman",         fontSize=7.8, leading=11.5,textColor=HexColor("#222222"), spaceAfter=0, alignment=TA_JUSTIFY)
BULLET   = S("bu",   fontName="Helvetica",           fontSize=7.4, leading=10.5,textColor=C_BODY, spaceAfter=2, alignment=TA_JUSTIFY)
EDU_DEG  = S("edg",  fontName="Helvetica-Bold",      fontSize=7.8, leading=10, textColor=C_BLACK)
EDU_SCH  = S("esc",  fontName="Helvetica",           fontSize=7.2, leading=9,  textColor=C_MID,  spaceAfter=2)
SKILL_B  = S("skb",  fontName="Helvetica-Bold",      fontSize=7.4, leading=10, textColor=C_BLACK)
SKILL_V  = S("skv",  fontName="Helvetica",           fontSize=7.4, leading=10, textColor=C_BODY)


def hr():
    return HRFlowable(width="100%", thickness=0.5, color=C_FAINT, spaceAfter=2)

def section(title):
    return [Spacer(1, 1*mm), Paragraph(title.upper(), SECTITLE), hr()]

def job(company_name, period_str, role_str, desc):
    tbl = Table(
        [[Paragraph(company_name, COMPANY), Paragraph(period_str, PERIOD)]],
        colWidths=[120*mm, 56*mm],
    )
    tbl.setStyle(TableStyle([
        ("VALIGN",       (0,0), (-1,-1), "BOTTOM"),
        ("LEFTPADDING",  (0,0), (-1,-1), 0),
        ("RIGHTPADDING", (0,0), (-1,-1), 0),
        ("TOPPADDING",   (0,0), (-1,-1), 0),
        ("BOTTOMPADDING",(0,0), (-1,-1), 0),
    ]))
    return [tbl, Paragraph(role_str, ROLE), Paragraph(desc, BODY)]


def build():
    doc = SimpleDocTemplate(
        OUTPUT, pagesize=A4,
        leftMargin=13*mm, rightMargin=13*mm,
        topMargin=7*mm,  bottomMargin=7*mm,
        title="Roberto Javier Aguirre Guardia — Anthropic Fellows Program",
    )
    story = []

    # ── HEADER ───────────────────────────────────────────────────────────────
    story.append(Paragraph("Roberto Javier Aguirre Guardia", NAME))
    story.append(Paragraph(
        "AI Economics Researcher &amp; Practitioner — Labor Markets, Digital Transformation, and AI Adoption in Emerging Economies",
        TITLEL))
    story.append(Paragraph(
        "aguirrerjg@gmail.com  &nbsp;&nbsp;|&nbsp;&nbsp;  +57 317 675 0419  "
        "&nbsp;&nbsp;|&nbsp;&nbsp;  Bogota, Colombia  "
        "&nbsp;&nbsp;|&nbsp;&nbsp;  linkedin.com/in/roberto-javier-aguirre-guadia",
        CONTACT))
    story.append(Spacer(1, 2.5*mm))

    # ── SUMMARY ──────────────────────────────────────────────────────────────
    story += section("Summary")
    story.append(Paragraph(
        "Systems engineer with MBA and 20+ years at the intersection of technology, management, and economic transformation across Latin America. "
        "Combines practitioner experience deploying AI-augmented workflows in fintech, healthcare, and public services with empirical research on how "
        "managers adopt, resist, and adapt to AI-driven change. Founder of AI4Managers — a 500+ member LATAM community generating longitudinal "
        "observational data on AI adoption curves in mid-market organizations. Applies Python, Claude API, and multi-agent orchestration to build "
        "the quantitative tools needed to study AI's economic and labor-market implications at scale.",
        SUMMARY))
    story.append(Spacer(1, 1*mm))

    # ── RESEARCH INTERESTS ───────────────────────────────────────────────────
    story += section("Research Interests")
    interests = [
        "<b>Labor market implications of AI in Latin America:</b> occupational displacement, task re-composition, and wage dynamics "
        "in management-intensive roles across fintech, banking, and public services.",
        "<b>AI adoption curves in financial services:</b> firm-level heterogeneity in adoption rates, productivity returns, "
        "and barriers in regulated industries (pensions, payments, insurance) in emerging markets.",
        "<b>Economic models for AI-driven productivity in management:</b> measuring how LLM-augmented decision-making alters "
        "span of control, organizational hierarchy, and output per manager — drawing on primary data from AI4Managers community.",
    ]
    for item in interests:
        story.append(Paragraph(f"&#x2022;&nbsp;&nbsp;{item}", BULLET))

    # ── EXPERIENCE ───────────────────────────────────────────────────────────
    story += section("Professional Experience")

    story += job(
        "DigitalHubAssist LLC",
        "Oct 2024 – Present",
        "Manager, AI Engineering & Research",
        "Lead engineering and research for a GenAI/SaaS platform serving medical professionals across LATAM. "
        "Designed and deployed multi-agent systems (conversational assistants, voice transcription, teleconsultation) "
        "in a high-sensitivity regulatory environment. Builds proprietary datasets on AI-augmented clinical workflows "
        "to assess productivity and safety outcomes — a direct empirical contribution to AI impact research."
    )

    story += job(
        "AI4Managers — Founder &amp; Lead Researcher",
        "2024 – Present",
        "Education Practitioner / Applied Researcher",
        "Founded and scaled a 500+ member LATAM community of managers navigating AI adoption. "
        "Generates primary observational data on how mid-market managers learn, adopt, and resist AI tools "
        "across industries including banking, logistics, and professional services. Conducts structured interviews "
        "and cohort analyses that constitute a de facto longitudinal study on managerial AI adoption in emerging economies."
    )

    story += job(
        "NTT DATA Colombia",
        "Apr 2021 – Oct 2024",
        "Consulting Manager — Financial Services &amp; Utilities",
        "Led Colombia's largest consulting engagement for Grupo AVAL (top-4 banking group), managing concurrent "
        "technology transformation programs. Directed AI-readiness assessments and process automation initiatives "
        "impacting 10,000+ employees. Maintained lowest staff turnover on account; delivered against financial KPIs "
        "in a macro environment of accelerating digital disruption and competitive pressure from neobanks."
    )

    story += job(
        "VASS Colombia",
        "Nov 2015 – Apr 2021",
        "Project Manager — Digital Transformation, Pension &amp; Financial Sectors",
        "Directed digitalization of Porvenir Private Pension Fund's member-facing channels — a program affecting "
        "millions of beneficiaries. Managed transition of legacy processes to digital-first workflows, generating "
        "first-hand evidence on workforce reskilling costs and productivity gains from technology adoption "
        "in a regulated savings environment."
    )

    story += job(
        "Tecnocom Colombia / GlobalHitss",
        "Aug 2012 – Nov 2015",
        "Digital Transformation Leader — Public Sector &amp; Insurance",
        "Directed judicial branch digitalization (PMP methodology) and led e-commerce and landing-page "
        "implementations for healthcare (COLSANITAS) and insurance (CARDIF/BNP Paribas). "
        "Early practitioner of platform economics applied to public services in Colombia."
    )

    # ── EDUCATION ────────────────────────────────────────────────────────────
    story += section("Education")

    edu_data = [
        ["Master of Business Administration (MBA)",           "Tecnologico de Monterrey, Mexico  |  2004"],
        ["B.Sc. Systems Engineering  —  Top Third of Class",  "Universidad de Lima, Peru  |  1999"],
    ]
    for deg, sch in edu_data:
        story.append(Paragraph(deg, EDU_DEG))
        story.append(Paragraph(sch, EDU_SCH))

    # ── KEY ACHIEVEMENTS ─────────────────────────────────────────────────────
    story += section("Key Achievements")
    achievements = [
        "Recognized by <i>Dinero</i> magazine (Colombia's leading business publication) as high-impact startup in LATAM healthcare AI.",
        "Selected keynote speaker at CLARO technology summit on digital transformation challenges in enterprise organizations.",
        "Founding professor, Innovation chair — Specialization in Project Management, Universidad Sergio Arboleda (Bogota).",
        "Certified Liferay Digital Experience expert; supervised 20+ platform migrations across financial and public-sector clients.",
    ]
    for item in achievements:
        story.append(Paragraph(f"&#x2022;&nbsp;&nbsp;{item}", BULLET))

    # ── TECHNICAL SKILLS ─────────────────────────────────────────────────────
    story += section("Technical Skills")

    skills = [
        ("Languages &amp; Libraries:", "Python (pandas, NumPy, requests, SQLite), SQL, Bash"),
        ("AI &amp; LLM Tooling:", "Claude API, OpenAI API, multi-agent orchestration, LLM prompt engineering, RAG pipelines"),
        ("Data &amp; Research:", "Apify scraping, SQLite-vec embeddings, Supabase, REST APIs, observational dataset construction"),
        ("Platforms &amp; Infra:", "Linux/Systemd, Docker, Vercel, GitHub Actions, SvelteKit"),
        ("Methodologies:", "Agile PM, PMP, mixed-methods research design, structured stakeholder interviews"),
    ]

    skill_rows = []
    for label, val in skills:
        row = Table(
            [[Paragraph(label, SKILL_B), Paragraph(val, SKILL_V)]],
            colWidths=[48*mm, 128*mm],
        )
        row.setStyle(TableStyle([
            ("VALIGN",       (0,0), (-1,-1), "TOP"),
            ("LEFTPADDING",  (0,0), (-1,-1), 0),
            ("RIGHTPADDING", (0,0), (-1,-1), 2),
            ("TOPPADDING",   (0,0), (-1,-1), 0),
            ("BOTTOMPADDING",(0,0), (-1,-1), 2),
        ]))
        skill_rows.append(row)

    for row in skill_rows:
        story.append(row)

    doc.build(story)
    print(f"PDF saved → {OUTPUT}")


if __name__ == "__main__":
    build()
