# system
from io import IOBase, StringIO
import os


# 3rd party
import click

# internal
from days import DayFactory

# import logging
# logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
# ch = logging.StreamHandler()
# logger.addHandler(ch)


@click.group(invoke_without_command=True)
@click.option('-d', '--day', required=True, type=click.IntRange(1, 31), metavar="<1..31>", help="Day you want to select.")
@click.option('-p', '--puzzle', required=True, type=click.IntRange(1, 2), metavar="<1|2>", help="Puzzle you want to run.")
@click.option('-i', '--input', required=True, type=click.Path(exists=True), help="Path to puzzle data.")
def cli(day: int, puzzle: int, input: str):
  filename = os.path.join(input, f"{day:02}_puzzle_{puzzle}.txt")
  if os.path.exists(filename):
    input_stream = open(filename, "r")
  else:
    input_stream = StringIO('')
  avocd = DayFactory(day, input_stream)

  try:
    print(avocd.run(puzzle))
  except NotImplementedError:
    print(f"Puzzle {puzzle} for day {day} not implemented.")


if __name__ == "__main__":
  # pylint: disable=no-value-for-parameter
  cli()

[((19, 1, 19, 41), 'click.group', 'click.group', (), '', False, 'import click\n'), ((24, 13, 24, 65), 'os.path.join', 'os.path.join', ({(24, 26, 24, 31): 'input', (24, 33, 24, 64): 'f"""{day:02}_puzzle_{puzzle}.txt"""'}, {}), "(input, f'{day:02}_puzzle_{puzzle}.txt')", False, 'import os\n'), ((25, 5, 25, 29), 'os.path.exists', 'os.path.exists', ({(25, 20, 25, 28): 'filename'}, {}), '(filename)', False, 'import os\n'), ((29, 10, 29, 39), 'days.DayFactory', 'DayFactory', ({(29, 21, 29, 24): 'day', (29, 26, 29, 38): 'input_stream'}, {}), '(day, input_stream)', False, 'from days import DayFactory\n'), ((28, 19, 28, 31), 'io.StringIO', 'StringIO', ({(28, 28, 28, 30): '""""""'}, {}), "('')", False, 'from io import IOBase, StringIO\n'), ((20, 49, 20, 70), 'click.IntRange', 'click.IntRange', ({(20, 64, 20, 65): '(1)', (20, 67, 20, 69): '(31)'}, {}), '(1, 31)', False, 'import click\n'), ((21, 52, 21, 72), 'click.IntRange', 'click.IntRange', ({(21, 67, 21, 68): '(1)', (21, 70, 21, 71): '(2)'}, {}), '(1, 2)', False, 'import click\n'), ((22, 51, 22, 74), 'click.Path', 'click.Path', (), '', False, 'import click\n')]