"""
Exportuje originální PDF puzzle z tabulky sudoku_killer pro porovnání.
"""

import sys
from pathlib import Path

sys.stdout.reconfigure(encoding="utf-8")
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "Knihovny"))

from mysql_db import connect_mysql

OUTPUT_DIR = Path(__file__).parent

conn = connect_mysql(database="puzzle")
cur = conn.cursor()
cur.execute(
    "SELECT puzzle_number, file_puzzle, file_solution "
    "FROM sudoku_killer WHERE puzzle_number = 31414"
)
row = cur.fetchone()
cur.close()
conn.close()

if not row:
    print("Puzzle 31414 nenalezen v sudoku_killer.")
else:
    num, pdf_puzzle, pdf_solution = row
    if pdf_puzzle:
        path = OUTPUT_DIR / f"original_{num}_puzzle.pdf"
        path.write_bytes(pdf_puzzle)
        print(f"Uloženo: {path}")
    if pdf_solution:
        path = OUTPUT_DIR / f"original_{num}_solution.pdf"
        path.write_bytes(pdf_solution)
        print(f"Uloženo: {path}")
