# -*- mode: python ; coding: utf-8 -*-
# PyInstaller Spec for HAD Digital MVP - Single Standalone Executable (.exe)
# Bundles pure Python HTTP server, embedded SQLite engine, responsive HTML/CSS/JS frontend,
# and CTCAE rules into a zero-external-dependency Windows executable.

import sys
from pathlib import Path

block_cipher = None

# Determine project root and MVP directory dynamically
spec_dir = Path(SPECPATH).resolve()
if spec_dir.name == "04_Build":
    project_root = spec_dir.parent
elif spec_dir.name == "MVP":
    project_root = spec_dir.parent
else:
    project_root = spec_dir

mvp_dir = project_root / "MVP"

datas = [
    (str(mvp_dir / "static"), "static"),
    (str(mvp_dir / "guidance"), "guidance"),
    (str(mvp_dir / "data" / "ctcae_rules.json"), "data"),
]

a = Analysis(
    [str(mvp_dir / "app.py")],
    pathex=[str(mvp_dir)],
    binaries=[],
    datas=datas,
    hiddenimports=[
        "adapters",
        "adapters.base",
        "adapters.stub",
        "adapters.glm",
        "http.server",
        "sqlite3",
        "hashlib",
        "json",
        "uuid",
        "datetime",
        "urllib.parse",
        "urllib.request",
        "urllib.error",
        "threading",
        "secrets",
        "email",
        "email.message",
        "email.parser",
        "email.utils",
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[
        "tkinter",
        "matplotlib",
        "scipy",
        "numpy",
        "pandas",
        "openpyxl",
        "PIL",
        "pytest",
        "playwright",
        "boto3",
        "botocore",
        "torch",
        "unittest",
        "xmlrpc",
        "pydantic",
        "fastapi",
        "starlette",
        "uvicorn",
        "sqlalchemy",
    ],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
    optimize=1,
)

pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name="HAD Digital",
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=False,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
