"""
mark_ltbs_212.py — Potvrzeno uživatelem:
  LTBS -> Rodina (rodinné fotky, názvy obsahují BUZALKA)
  212  -> Odpad-dokumenty (skeny smluv Confidentiality Agreement)
"""
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")

B = "/mnt/user/ZalohaVsechObrazku/Tower1/#ColdData/"
RULES = [
    ("LTBS", B + "LTBS/%", True,  "Rodina"),
    ("212",  B + "212/%",  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:6s} -> {kat:16s} (wanted={wanted}): {cur.rowcount:,}")
conn.close()
print("Hotovo.")
