import click

from qrtransfert.qr_encode import encode as qr_encode
from qrtransfert.qr_decode import decode as qr_decode

from qrtransfert.constants import DEFAULT_THRESHOLD, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT, DEFAULT_FPS


@click.group()
def cli():
  pass

@cli.command()
@click.option("-f", "file", required=True, type=str, help="Path of a movie file to decode")
@click.option("-ct", "--correction-threshold", default=DEFAULT_THRESHOLD, help="Image correction threshold", type=click.IntRange(0, 255, clamp=True))
@click.option("-fps", "--fps-to-decode", default=DEFAULT_FPS, help="Desired fps for decode QRCode", type=click.IntRange(1, 60, clamp=True))
@click.option("-d", "--debug", is_flag=True, help="Only display QRCode to adjust the threshold variable")
def decode(file, correction_threshold, fps_to_decode, debug):
  """ Decode a video file with QRCodes info a single file """
  qr_decode(file, correction_threshold, fps_to_decode, debug)

@cli.command()
@click.option("-f", "file", required=True, type=click.File(mode='rb'), help="Path of a single file to transfert")
@click.option("-c", "--qr-color", is_flag=True, help="Use color QRCode to increase by 3 the data content in a QRCode")
@click.option("-t", "--terminal", is_flag=True, help="Display QRCode in terminal")
@click.option("-qmax", "--qr-max-version", default=20, help="Maximun version of the QRCode to generate", type=click.IntRange(1, 40, clamp=True))
@click.option("-qcor", "--qr-correction", default="M", help="Define the error correction level for the QRCode", type=click.Choice(['L', 'M', 'Q', 'H'], case_sensitive=False))
@click.option("-l", "--loop-delay", default=0.6, help="Set the loop rotation delay for the QRCodes in seconds", type=float)
@click.option("-ww", "--window-width", default=DEFAULT_WINDOW_WIDTH, help="Width of the windows to display QRCodes", type=int)
@click.option("-wh", "--window-height", default=DEFAULT_WINDOW_HEIGHT, help="Height of the windows to display QRCodes", type=int)
@click.option("-o", "--out-to-file", help="Output filename", type=str)
def encode(file, qr_color, terminal, qr_max_version, qr_correction, loop_delay, window_width, window_height, out_to_file):
  """ Transfert a single file using QRCodes """
  qr_encode(file, qr_color, terminal, qr_max_version, qr_correction, loop_delay, window_width, window_height, out_to_file)

if __name__ == "__main__":
  cli()