#!/usr/bin/env python3
"""Quick CI branding checks on generated report HTML."""
from __future__ import annotations

import re
import sys
from pathlib import Path

CONTRACTIONS = re.compile(r"\b(don't|won't|can't|isn't|aren't)\b", re.I)


def main() -> int:
    base = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("Reports/generated/ci-test")
    stem = sys.argv[2] if len(sys.argv) > 2 else "Overdrive_2026-06-05"
    email = (base / f"{stem}_email.html").read_text(encoding="utf-8")
    full = (base / f"{stem}_full.html").read_text(encoding="utf-8")
    body = (base / f"{stem}_email_body.html").read_text(encoding="utf-8")
    pdf = base / f"{stem}.pdf"

    checks: list[tuple[str, bool]] = [
        ("email navy header #002A41", "#002A41" in email),
        ("email no old teal #0f4c4a", "#0f4c4a" not in email.lower()),
        ("email accent #0089D6", "#0089D6" in email),
        ("email background #EDEDED", "#EDEDED" in email),
        ("email Poppins font", "Poppins" in email),
        ("email embedded white logo", "data:image/png;base64," in email),
        ("email summary 14px", "font-size:14px" in email),
        ("body dark logo embedded", "data:image/png;base64," in body),
        ("body Poppins font", "Poppins" in body),
        ("full Poppins + accent", "Poppins" in full and "#0089D6" in full),
        ("full dark logo in header", 'class="brand-logo"' in full and "data:image/png;base64," in full),
        ("full no old teal", "#0f4c4a" not in full.lower()),
        ("pdf exists", pdf.is_file() and pdf.stat().st_size > 10_000),
        ("email template copy: no contractions", not CONTRACTIONS.search(email[:12000])),
        ("body template copy: no contractions", not CONTRACTIONS.search(body)),
    ]

    passed = sum(1 for _, ok in checks if ok)
    for name, ok in checks:
        print(f"  {'OK' if ok else 'FAIL'}  {name}")
    print(f"\n{passed}/{len(checks)} checks passed")
    return 0 if passed == len(checks) else 1


if __name__ == "__main__":
    raise SystemExit(main())
