"""
mark_synology_zbytek.py — Dokončí SynologyMaly:
  Public/Dropbox  -> Rodina (chceme, potvrzeno uživatelem)
  music/web/video -> Odpad-cache (obaly, web obrázky)
"""
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")

BASE = "/mnt/user/ZalohaVsechObrazku/Tower1/#ColdData/SynologyMaly/"

RULES = [
    ("Public/Dropbox", BASE + "Public/Dropbox/%", True,  "Rodina"),
    ("music",          BASE + "music/%",          False, "Odpad-cache"),
    ("web",            BASE + "web/%",            False, "Odpad-cache"),
    ("video",          BASE + "video/%",          False, "Odpad-cache"),
]

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:16s} -> {kat:12s} (wanted={wanted}): {cur.rowcount:,}")

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