#!/usr/bin/env python3
"""Point d'entrée de la GUI V6 de Pseudonymisation.

Usage :
    python Pseudonymisation_Gui_V6.py            # lance la fenêtre
    python Pseudonymisation_Gui_V6.py --self-test  # importe l'app, sort 0, sans fenêtre

Le mode ``--self-test`` vérifie que tout le socle GUI V6 s'importe correctement
(utile en CI / build sans display). Il n'ouvre aucune fenêtre.
"""

from __future__ import annotations

import sys


def _self_test() -> int:
    """Importe les modules du socle GUI V6 sans créer de fenêtre."""
    from gui_v6 import (  # noqa: F401
        app,
        config_state,
        engine_bridge,
        license_client,
        license_store,
        machine_id,
        processing_runner,
        theme,
        ui_kit,
    )
    from gui_v6.tabs import tab_about, tab_config, tab_usage  # noqa: F401

    # Sanity check des contrats publics du socle.
    assert hasattr(app, "AnonymisationApp")
    assert hasattr(license_client, "LicenseClient")
    assert hasattr(license_client, "LicenseStatus")
    assert hasattr(license_store, "LicenseStore")
    assert hasattr(processing_runner, "ProcessingRunner")
    assert hasattr(engine_bridge, "make_process_fn")
    assert hasattr(config_state, "ConfigState")
    assert hasattr(machine_id, "default_machine_id")
    assert hasattr(ui_kit, "Card")
    assert hasattr(theme, "PALETTES") and set(theme.PALETTES) >= {"sombre", "clair", "medical", "neutre"}
    assert hasattr(tab_about, "AboutTab")
    assert hasattr(tab_config, "ConfigTab")
    assert hasattr(tab_usage, "UsageTab")
    print("GUI V6 self-test OK")
    return 0


def main(argv=None) -> int:
    argv = list(sys.argv[1:] if argv is None else argv)
    if "--self-test" in argv:
        return _self_test()

    from gui_v6.app import AnonymisationApp

    application = AnonymisationApp()
    application.mainloop()
    return 0


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