"""
mark_tatinek_cast1.py — Tatinek U, rozhodnuté části (potvrzeno uživatelem):
  Fractal (iPhone 13)          -> Rodina (chceme)
  DarthAnihilator + Screenshots-> Odpad-screenshot
  Duplicates/Compass (dokumenty)-> Odpad-dokumenty
"""
import sys
import psycopg2

sys.stdout.reconfigure(encoding="utf-8")

DB = dict(host="192.168.1.76", port=5432, user="vladimir.buzalka",
          password="Vlado7309208104++", database="fotky_buzalkovi")

T = "/mnt/user/ZalohaVsechObrazku/Tower1/#ColdData/Tatinek U/"

RULES = [
    ("Fractal (iPhone)",   T + "D/!!!Days/%Fractal%", True,  "Rodina"),
    ("DarthAnihilator",    T + "DarthAnihilator/%",   False, "Odpad-screenshot"),
    ("Screenshots",        T + "Screenshots/%",       False, "Odpad-screenshot"),
    ("Compass dokumenty",  T + "Duplicates/Compass/%",False, "Odpad-dokumenty"),
]

conn = psycopg2.connect(**DB)
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cur = conn.cursor()

for popis, like, wanted, kat in RULES:
    cur.execute("""
        UPDATE photos p
        SET wanted = %s, category = %s
        FROM zaloha_obrazku z
        WHERE p.zaloha_id = z.id
          AND z.cesta_zalohy LIKE %s
          AND (p.wanted IS DISTINCT FROM %s OR p.category IS DISTINCT FROM %s)
    """, (wanted, kat, like, wanted, kat))
    print(f"  {popis:20s} -> {kat:18s} (wanted={wanted}): {cur.rowcount:,}")

conn.close()
print("Hotovo.")
