"""
update_wanted.py — označuje fotky wanted=TRUE a nastavuje category.
Spusť a uprav seznam pravidel podle potřeby.
"""
import psycopg2

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

conn = psycopg2.connect(**DB)
conn.autocommit = True
cur = conn.cursor()

rules = [
    # (popis, SQL WHERE, category)
    # ── Samsung ──────────────────────────────────────────────────────────────
    (
        "Samsung SM-G935F / A520F / A525F / J500FN / I8190N / S7560 / S5230",
        "camera_make IN ('samsung', 'SAMSUNG', 'Samsung') AND camera_model IN "
        "('SM-G935F','SM-A520F','SM-A525F','SM-J500FN','GT-I8190N','GT-S7560','GT-S5230')",
        "Rodina",
    ),
    # ── Profesionální / cizí ─────────────────────────────────────────────────
    (
        "Nikon D5 / D4 / D700 / D300 / D800 / D500",
        "camera_make = 'NIKON CORPORATION' AND camera_model IN "
        "('NIKON D5','NIKON D4','NIKON D700','NIKON D300','NIKON D800','NIKON D500')",
        "Rodina",
    ),
    (
        "Canon EOS-1D X III / 450D / 600D / R6 / 5D IV / 5D / 40D / 20D",
        "camera_make = 'Canon' AND camera_model IN "
        "('Canon EOS-1D X Mark III','Canon EOS 450D','Canon EOS 600D','Canon EOS R6',"
        "'Canon EOS 5D Mark IV','Canon EOS 5D','Canon EOS 40D','Canon EOS 20D')",
        "Rodina",
    ),
    (
        "Sony ILCE-1 (Alpha 1)",
        "camera_make = 'SONY' AND camera_model = 'ILCE-1'",
        "Rodina",
    ),
    (
        "Panasonic DC-S5",
        "camera_make = 'Panasonic' AND camera_model = 'DC-S5'",
        "Rodina",
    ),
    # ── Ostatní kompakty ─────────────────────────────────────────────────────
    (
        "Panasonic DMC-FZ5",
        "camera_make = 'Panasonic' AND camera_model = 'DMC-FZ5'",
        "Rodina",
    ),
    (
        "Canon PowerShot S40",
        "camera_make = 'Canon' AND camera_model = 'Canon PowerShot S40'",
        "Rodina",
    ),
    (
        "Canon PowerShot A40",
        "camera_make = 'Canon' AND camera_model = 'Canon PowerShot A40'",
        "Rodina",
    ),
    (
        "Panasonic DMC-FX33",
        "camera_make = 'Panasonic' AND camera_model = 'DMC-FX33'",
        "Rodina",
    ),
    (
        "NIKON D80",
        "camera_make = 'NIKON CORPORATION' AND camera_model = 'NIKON D80'",
        "Rodina",
    ),
    (
        "GoPro HERO6 Black",
        "camera_make = 'GoPro' AND camera_model = 'HERO6 Black'",
        "Rodina",
    ),
    (
        "Microsoft Lumia 930",
        "camera_make = 'Microsoft' AND camera_model = 'Lumia 930'",
        "Rodina",
    ),
    (
        "Panasonic DMC-FX3",
        "camera_make = 'Panasonic' AND camera_model = 'DMC-FX3'",
        "Rodina",
    ),
    (
        "Sony DSC-T77",
        "camera_make = 'SONY' AND camera_model = 'DSC-T77'",
        "Rodina",
    ),
    (
        "Olympus C120/D380",
        "camera_make = 'OLYMPUS OPTICAL CO.,LTD' AND camera_model = 'C120,D380'",
        "Rodina",
    ),
    (
        "Sony DSC-WX50",
        "camera_make = 'SONY' AND camera_model = 'DSC-WX50'",
        "Rodina",
    ),
    (
        "Sony CYBERSHOT",
        "camera_make = 'SONY' AND camera_model = 'CYBERSHOT'",
        "Rodina",
    ),
    (
        "Casio EX-Z6",
        "camera_make = 'CASIO COMPUTER CO.,LTD.' AND camera_model = 'EX-Z6'",
        "Rodina",
    ),
    (
        "Olympus C765UZ",
        "camera_make = 'OLYMPUS CORPORATION' AND camera_model = 'C765UZ'",
        "Rodina",
    ),
    (
        "Nikon E990",
        "camera_make = 'NIKON' AND camera_model = 'E990'",
        "Rodina",
    ),
]

for popis, where, category in rules:
    cur.execute(f"""
        UPDATE photos
        SET wanted   = TRUE,
            category = %s
        WHERE {where}
          AND (wanted = FALSE OR category IS DISTINCT FROM %s)
    """, (category, category))
    print(f"{popis}: {cur.rowcount:,} řádků → wanted=TRUE, category='{category}'")

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