#!/usr/bin/env python3
"""
Synex Snapshots launcher.

Supports running both from the development source tree and from an installed
system package.
"""

from __future__ import annotations

import sys
from pathlib import Path


def configure_python_path() -> None:
    """
    Add the appropriate application library directory to sys.path.

    Development layout:
        <project>/src/bin/synex-snapshots
        <project>/src/synexsnapshots/
        <project>/src/ui/

    Installed layout:
        /usr/bin/synex-snapshots
        /usr/lib/synex-snapshots/synexsnapshots/
        /usr/lib/synex-snapshots/ui/
    """

    launcher_path = Path(__file__).resolve()

    development_lib = launcher_path.parent.parent
    installed_lib = Path("/usr/lib/synex-snapshots")

    if (development_lib / "synexsnapshots").is_dir():
        sys.path.insert(0, str(development_lib))
        return

    if (installed_lib / "synexsnapshots").is_dir():
        sys.path.insert(0, str(installed_lib))
        return

    raise RuntimeError(
        "Unable to locate the Synex Snapshots application modules."
    )


def main() -> int:
    configure_python_path()

    from synexsnapshots.app import main as application_main

    return application_main()


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