import argparse
import logging
from pathlib import Path

from unwind import db
from unwind.imdb_import import import_from_file

log = logging.getLogger(__name__)

name = "import-imdb-dataset"
help = """Import IMDb datasets.
New datasets available from https://www.imdb.com/interfaces/.
"""


def add_args(cmd: argparse.ArgumentParser) -> None:
    cmd.add_argument("--basics", metavar="basics_file.tsv.gz", type=Path, required=True)
    cmd.add_argument(
        "--ratings", metavar="ratings_file.tsv.gz", type=Path, required=True
    )


async def main(args: argparse.Namespace) -> None:
    basics_path: Path = args.basics
    ratings_path: Path = args.ratings

    await db.open_connection_pool()

    await import_from_file(basics_path=basics_path, ratings_path=ratings_path)

    await db.close_connection_pool()
