"""
mark_xperie_vladko.py — Osobní složky v #ColdData, chceme zachovat:
  Honza fotky z Xperie -> kamarad Jan Luxemburk  -> category 'Kamaradi'
  VladkoSoubory        -> syn Vladimir Buzalka ml -> category 'Rodina'
Obojí wanted=TRUE (potvrzeno uživatelem).
"""
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/"

RULES = [
    ("Honza fotky z Xperie", BASE + "Honza fotky z Xperie/%", "Kamaradi"),
    ("VladkoSoubory",        BASE + "VladkoSoubory/%",        "Rodina"),
]

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

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

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