"""
hwrt, the handwriting recognition toolkit, is a set of executable scripts
and Python modules that are useful for handwriting recognition.

For train.py, test.py you will need an internal toolkit for training of
neural networks. The backup.py script is only useful if you have a
website like write-math.com to collect recordings.
"""

# Core Library modules
import logging
import os
import sys

# Third party modules
import click

# First party modules
import hwrt
import hwrt.utils

logging.basicConfig(
    format="%(asctime)s %(levelname)s %(message)s",
    level=logging.DEBUG,
    stream=sys.stdout,
)


@click.group()
@click.version_option(version=hwrt.__version__)
def entry_point():
    pass


model_option = click.option(
    "-m",
    "--model",
    default=hwrt.utils.default_model(),
    show_default=True,
    type=click.Path(dir_okay=True, file_okay=False, exists=True),
    help="where is the model folder (with a info.yml)?",
)


@entry_point.command()
def selfcheck():
    """Self-check of the HWRT toolkit."""
    # First party modules
    import hwrt.selfcheck

    hwrt.selfcheck.main()


@entry_point.command()
@click.option(
    "-i",
    "--id",
    "raw_data_id",
    default=292293,
    type=int,
)
@click.option(
    "--mysql",
    "mysql_cfg",
    default="mysql_online",
    type=str,
    help="which mysql configuration should be used?",
)
@model_option
@click.option(
    "-l",
    "--list",
    "list_ids",
    default=False,
    help="list all raw data IDs / symbol IDs",
    is_flag=True,
)
@click.option(
    "-s",
    "--server",
    "contact_server",
    default=False,
    help="contact the MySQL server",
    is_flag=True,
)
@click.option(
    "-r",
    "--raw",
    "show_raw",
    default=False,
    help="show the raw recording (without preprocessing)",
    is_flag=True,
)
def view(raw_data_id, mysql_cfg, model, list_ids, contact_server, show_raw):
    """Display raw preprocessed recordings."""
    # First party modules
    import hwrt.view

    hwrt.view.main(
        list_ids=list_ids,
        model=model,
        contact_server=contact_server,
        raw_data_id=raw_data_id,
        show_raw=show_raw,
        mysql_cfg=mysql_cfg,
    )


@entry_point.command()
def download():
    """Download the raw data to start analyzation / traning."""
    # First party modules
    import hwrt.download

    hwrt.download.main()


@entry_point.command()
@model_option
@click.option(