from pathlib import Path

from loguru import logger
from typer import Typer

from huesoporro.actions.import_from_vod import ImportFromVODAction
from huesoporro.actions.misc.update_version_action import UpdateVersionAction
from huesoporro.settings import Settings
from huesoporro.svc.clean_cc_svc import CleanCCSvc
from huesoporro.svc.download_closed_captions import DownloadClosedCaptionsSvc

app = Typer()


@app.command()
def import_vod(channel_name: str, youtube_url: str, db_path: Path | None = None):
    logger.info(f"Importing VOD closed captions for {channel_name} from {youtube_url}")
    s = Settings.get(db_filepath=db_path)
    import_from_vod_action = ImportFromVODAction(
        download_closed_captions_svc=DownloadClosedCaptionsSvc(),
        clean_cc_svc=CleanCCSvc(),
        s=s,
    )
    for cc_filepath in import_from_vod_action.run(channel_name, youtube_url):
        logger.info(f"Closed captions imported from {cc_filepath}")


@app.command()
def update_version(version: str, dry_run: bool = False):
    UpdateVersionAction().run(version, dry_run)
