import uvicorn
from fastapi import FastAPI

from .app import create_app
from .config import parse_cli_settings


def create_cli_app() -> FastAPI:
    """Create an app from CLI settings for Uvicorn's reload process."""
    return create_app(settings=parse_cli_settings())


def main() -> None:
    settings = parse_cli_settings()
    application = "transcription.__main__:create_cli_app" if settings.reload else create_app(settings=settings)
    uvicorn.run(
        application,
        factory=settings.reload,
        host=settings.host,
        port=settings.port,
        log_level=settings.log_level,
        reload=settings.reload,
    )


if __name__ == "__main__":
    main()
