"""albus server / albus studio -- Server and studio launch commands."""

from __future__ import annotations

import sys

from server.transport.cli._models import ServerArgs, StudioArgs
from server.transport.server import main as server_main
from server.transport.studio import run_studio


def cmd_server(args: ServerArgs) -> int:
    """Run the Albus server."""
    argv = ["albus-server"]
    if args.host:
        argv.extend(["--host", args.host])
    if args.port:
        argv.extend(["--port", str(args.port)])
    if args.debug:
        argv.append("--debug")
    if args.log_level:
        argv.extend(["--log-level", str(args.log_level)])

    sys.argv = argv
    server_main()
    return 0


def cmd_studio(args: StudioArgs) -> int:
    """Launch interactive studio."""
    return run_studio(host=args.host, port=args.port, thread_id=args.thread_id)
