"""
ABSFUYU CLI
-----------
Image

Version: 6.8.0
Date updated: 26/04/2026 (dd/mm/yyyy)
"""

# Module Package
# ---------------------------------------------------------------------------
__all__ = ["img_group"]


# Library
# ---------------------------------------------------------------------------
from pathlib import Path

import click


# CLI
# ---------------------------------------------------------------------------
@click.command(name="cv")
@click.argument("dir_path", type=str)
@click.argument("to_format", type=str)
@click.option(
    "--recursive",
    "-r",
    "recursive_mode",
    type=bool,
    default=False,
    is_flag=True,
    show_default=True,
    help="Convert every file in the folder (including child folder)",
)
@click.option(
    "--multithread",
    "-x",
    "multithreaded",
    type=bool,
    default=False,
    is_flag=True,
    show_default=True,
    help="Run in multithreaded mode",
)
def convert_img(dir_path: str, to_format: str, recursive_mode: bool, multithreaded: bool) -> None:
    """Convert image in directory"""
    from absfuyu.extra.img.converter import ImgConverter

    engine = ImgConverter(Path(dir_path).resolve(), recursive=recursive_mode)
    if multithreaded:
        engine.img_convert_multithread(to_format)
    else:
        engine.img_convert(to_format)
    click.echo("Done")


@click.command(name="rd")
@click.argument("dir_path", type=str)
@click.option(
    "--dryrun",
    "-d",
    "dry_run",
    type=bool,
    default=False,
    is_flag=True,
    show_default=True,
    help="Simulate deleting only",
)
@click.option(
    "--recursive",
    "-r",
    "recursive_mode",
    type=bool,
    default=False,
    is_flag=True,
    show_default=True,
    help="Scan for every file in the folder (including child folder)",
)
@click.option(
    "--threshold",
    "-t",
    "threshold",
    type=int,
    default=5,
    show_default=True,
    help="Threshold: 0 for exact image, 5 to 10 for light edit",
)
@click.option(
    "--keepmode",
    "-k",
    "keep_mode",
    type=click.Choice(["first", "last", "best"]),
    default="best",
    show_default=True,
    help="Keep mode",
)
def remove_dup_img(dir_path: str, threshold: bool, recursive_mode: bool, keep_mode: str, dry_run: bool) -> None:
    """Remove duplicate images in directory"""
    from absfuyu.extra.img.dup_check import DirectoryRemoveDuplicateImageMixin as DRDI

    engine = DRDI(Path(dir_path).resolve())
    engine.remove_duplicate_images(threshold=threshold, recursive=recursive_mode, keep_mode=keep_mode, dry_run=dry_run)
    click.echo("Done")


@click.group(name="img")
def img_group() -> None:
    """Image related"""
    pass


img_group.add_command(convert_img)
img_group.add_command(remove_dup_img)
