#!/usr/bin/env python3
"""Run the gRPC server with auto-reload.

Watches only the core server code (and alembic.ini) to avoid noisy directories.
"""

from __future__ import annotations

import subprocess
import sys
from pathlib import Path

from watchfiles import PythonFilter, run_process


def run_server() -> None:
    """Start the gRPC server process."""
    subprocess.run([sys.executable, "-m", "noteflow.grpc.server"], check=False)


def main() -> None:
    root = Path(__file__).resolve().parents[1]
    watch_paths = [root / "src" / "noteflow", root / "alembic.ini"]
    existing_paths = [str(path) for path in watch_paths if path.exists()] or [
        str(root / "src" / "noteflow")
    ]

    run_process(
        *existing_paths,
        target=run_server,
        watch_filter=PythonFilter(),
    )


if __name__ == "__main__":
    main()
