#!/usr/bin/env python3
"""Generate Roberto Aguirre CV for Revolut S&O role — 1 page, reportlab."""

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-revolut.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)

# Slightly tighter sizes to fit 1 page
NAME     = S("name", fontName="Helvetica-Bold",    fontSize=18, leading=22, textColor=C_BLACK, spaceAfter=1)
TITLEL   = S("tl",   fontName="Helvetica",          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="Helvetica",          fontSize=7.6,leading=11, textColor=HexColor("#222222"), spaceAfter=0, alignment=TA_JUSTIFY)
SKILLB   = S("skb",  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)
CERT     = S("cert", fontName="Helvetica",          fontSize=7.4,leading=10.5,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 — Strategy & Operations Manager",
    )
    story = []

    # ── HEADER ───────────────────────────────────────────────────────────────
    story.append(Paragraph("Roberto Javier Aguirre Guardia", NAME))
    story.append(Paragraph(
        "Strategy and Operations Manager — Fintech, Payments and Digital Economy", TITLEL))
    story.append(Paragraph(
        "aguirrerjg@gmail.com  &nbsp;&nbsp;|&nbsp;&nbsp;  +57 317 675 0419  "
        "&nbsp;&nbsp;|&nbsp;&nbsp;  Bogota, Colombia (open to relocate)  "
        "&nbsp;&nbsp;|&nbsp;&nbsp;  linkedin.com/in/roberto-javier-aguirre-guadia",
        CONTACT))
    story.append(Spacer(1, 2.5*mm))
    story.append(HRFlowable(width="100%", thickness=1.5, color=C_BLACK, spaceAfter=3))

    # ── SUMMARY ──────────────────────────────────────────────────────────────
    story += section("Professional Summary")
    story.append(Paragraph(
        "Strategy and Operations professional with 15+ years of end-to-end ownership in fintech, "
        "digital payments and fast-scaling technology environments across LATAM. Deep understanding "
        "of the payments ecosystem — card payments, acquiring, APMs, settlement, FX and cross-border "
        "flows — with proven ability to translate strategic initiatives into measurable operational "
        "outcomes. Experienced driving ambiguous, zero-to-one programs: defining KPIs, aligning "
        "stakeholders from engineering to C-suite, managing vendors and tracking performance against "
        "targets. Systems Engineer with MBA; SQL and Python for data-driven decision-making. "
        "Thrives in high-velocity environments where ownership and speed of execution matter.",
        SUMMARY))

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

    story += job(
        "DIGITALHUBASSIST LLC", "Oct 2024 to Present",
        "Head of Strategy, Product and AI Operations",
        "Built and operated a GenAI/SaaS platform for healthcare professionals across LATAM from the "
        "ground up. Owned full program lifecycle: strategy, roadmap, vendor selection, launch and "
        "post-launch optimization. Designed operational frameworks to track activation, retention and "
        "unit economics. Coordinated cross-functional squads under ambiguous conditions with no prior "
        "playbook. Established partnerships with third-party AI providers and managed contracts end-to-end."
    )
    story += job(
        "NTTDATA COLOMBIA", "Apr 2021 to Oct 2024",
        "Delivery and Strategy Manager — Banking (Grupo AVAL)",
        "Led strategy and operations for the firm's largest engagement in Colombia, serving Grupo AVAL — "
        "a banking conglomerate with 40M+ clients. Oversaw simultaneous delivery tracks, owned P&amp;L, "
        "and maintained the lowest staff turnover in the practice. Recovered financial viability of a "
        "critical client project (Promigas) through operational restructuring. Built C-level "
        "relationships as strategic counterpart to banking and fintech stakeholders."
    )
    story += job(
        "VASS COLOMBIA", "Apr 2018 to Apr 2021",
        "Digital Operations and Product Manager — Financial Services",
        "Directed digital channel operations for Porvenir, Colombia's largest private pension fund. "
        "Led delivery of payment and self-service solutions for millions of users. Coordinated "
        "integration with payment processors and local APMs; defined KPIs to reduce transaction "
        "friction and improve settlement rates. Won LATAMDIGITAL 2019 award. Led migration of "
        "transactional portals to Azure without service interruption."
    )
    story += job(
        "GLOBALHITSS", "Nov 2015 to Apr 2018",
        "Digital Operations Lead — Payments and Financial Platforms",
        "Led operational delivery of digital commerce and banking platforms for CARDIF and COLSANITAS. "
        "Coordinated integration with payment processors and financial APIs; tracked performance "
        "against SLAs, conversion targets and operational budgets. Worked across tech, legal, "
        "operations and marketing to ensure compliant and high-performance payment flows."
    )
    story += job(
        "TECNOCOM COLOMBIA", "Aug 2012 to Nov 2015",
        "Digital Transformation Program Lead",
        "Directed digitalization programs for Colombia's Judicial Branch across multiple public "
        "entities. Defined scope, built business cases, managed stakeholder alignment and led "
        "cross-institutional delivery on time and within budget with no existing operational "
        "infrastructure."
    )

    # ── SKILLS ───────────────────────────────────────────────────────────────
    story += section("Core Skills")

    def sk(label, text):
        return Paragraph(f"<b>{label}:</b> {text}", SKILLB)

    sk_data = [[
        sk("Payments and Fintech",
           "Card payments, acquiring, APMs, PSPs, settlement and reconciliation, FX and "
           "cross-border flows, open banking, digital wallets, LATAM regulatory frameworks "
           "(Peru, Colombia)"),
        sk("Strategy and Operations",
           "OKR/KPI definition, operational performance tracking, vendor management, "
           "P&amp;L ownership, business case development, go-to-market execution, "
           "post-launch iteration"),
    ], [
        sk("Data and Tools",
           "SQL for operational analytics, Python (scripting/automation), "
           "AI-augmented workflows, Jira, Confluence, Agile/Scrum, PMP methodology"),
        sk("Cross-functional Leadership",
           "Stakeholder alignment (engineering, finance, legal, commercial), C-level "
           "communication, multicultural global teams, ambiguity management in fast-paced "
           "environments"),
    ]]

    sk_tbl = Table(sk_data, colWidths=[90*mm, 90*mm])
    sk_tbl.setStyle(TableStyle([
        ("VALIGN",       (0,0), (-1,-1), "TOP"),
        ("LEFTPADDING",  (0,0), (-1,-1), 0),
        ("RIGHTPADDING", (0,0), (0,-1),  7),
        ("RIGHTPADDING", (1,0), (1,-1),  0),
        ("TOPPADDING",   (0,0), (-1,-1), 0),
        ("BOTTOMPADDING",(0,0), (-1,-1), 0),
    ]))
    story.append(sk_tbl)

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

    edu_rows = [
        [
            [Paragraph("Master of Business Administration (MBA)", EDU_DEG),
             Paragraph("Tecnologico de Monterrey, Mexico", EDU_SCH)],
            Paragraph("2004", PERIOD),
        ],
        [
            [Paragraph("Bachelor of Science, Systems Engineering", EDU_DEG),
             Paragraph("Universidad de Lima, Peru — Top Third of Graduating Class", EDU_SCH)],
            Paragraph("1999", PERIOD),
        ],
    ]
    edu_tbl = Table(edu_rows, colWidths=[152*mm, 28*mm])
    edu_tbl.setStyle(TableStyle([
        ("VALIGN",       (0,0), (-1,-1), "TOP"),
        ("LEFTPADDING",  (0,0), (-1,-1), 0),
        ("RIGHTPADDING", (0,0), (-1,-1), 0),
        ("TOPPADDING",   (0,0), (-1,-1), 0),
        ("BOTTOMPADDING",(0,0), (-1,-1), 0),
    ]))
    story.append(edu_tbl)

    # ── CERTIFICATIONS ────────────────────────────────────────────────────────
    story += section("Certifications and Recognition")

    certs = [
        "Project Management Professional (PMP), PMI",
        "AI for Product Management, Pendo and Mind the Product",
        "Generative AI Fundamentals, Google Cloud",
        "Digital Experience Platform Expert, Liferay",
        "Speaker, CLARO Technology Summit — digital transformation and operations",
        "Founding Professor, Innovation in PM, Universidad Sergio Arboleda",
        "Featured in DINERO magazine, MedicalHubAssist regional digital health impact",
        "Bilingual: Spanish (native), English (fluent, C1)",
    ]
    col1, col2 = certs[:4], certs[4:]
    c_rows = []
    for i in range(max(len(col1), len(col2))):
        l = Paragraph(f"\u25aa  {col1[i]}", CERT) if i < len(col1) else Spacer(1,1)
        r = Paragraph(f"\u25aa  {col2[i]}", CERT) if i < len(col2) else Spacer(1,1)
        c_rows.append([l, r])

    c_tbl = Table(c_rows, colWidths=[90*mm, 90*mm])
    c_tbl.setStyle(TableStyle([
        ("VALIGN",       (0,0), (-1,-1), "TOP"),
        ("LEFTPADDING",  (0,0), (-1,-1), 0),
        ("RIGHTPADDING", (0,0), (0,-1),  7),
        ("RIGHTPADDING", (1,0), (1,-1),  0),
        ("TOPPADDING",   (0,0), (-1,-1), 1),
        ("BOTTOMPADDING",(0,0), (-1,-1), 1),
    ]))
    story.append(c_tbl)

    doc.build(story)

    # ── VERIFY ───────────────────────────────────────────────────────────────
    import os
    from pypdf import PdfReader
    size = os.path.getsize(OUTPUT)
    r = PdfReader(OUTPUT)
    pages = len(r.pages)
    print(f"PDF: {OUTPUT}")
    print(f"Size: {size} bytes ({size/1024:.1f} KB)")
    print(f"Pages: {pages}")


if __name__ == "__main__":
    build()
