# -*- coding: utf-8 -*-
# =============================================================================
# Nazev:   mark_sipiq_sent_v1.0.py
# Verze:   1.0
# Datum:   2026-06-09
# Popis:   Predřadi do STATUS radek "09JUN2026: SIPIQ odeslán" u 14 investigatoru
#          (krok 5 -> po odeslani SIPIQ). Idempotentni (nepridava 2x stejny den).
#          Po zapisu spustit classify_krok_v1.0.py --apply (prejdou na KROK 6).
# Pouziti: python mark_sipiq_sent_v1.0.py            (dry-run)
#          python mark_sipiq_sent_v1.0.py --apply     (zapise)
# =============================================================================

import os
import sys
from pymongo import MongoClient
from bson import ObjectId

MONGO_URI = os.environ.get("MONGO_URI", "mongodb://192.168.1.76:27017")
LINE = "09JUN2026: SIPIQ odeslán"

IDS = [
    ("6a1c4275aa46d8b608065cec", "Lukac"),
    ("6a19832b5fc221351825794f", "Hlavaty"),
    ("6a19832b5fc2213518257954", "Fedurco"),
    ("6a198b661218c31ab0f5ba43", "Tichy"),
    ("6a19832b5fc221351825796e", "Falc"),
    ("6a198b661218c31ab0f5ba41", "Pesta"),
    ("6a198b661218c31ab0f5ba45", "Jungwirthova"),
    ("6a19832b5fc2213518257950", "Matous"),
    ("6a19832b5fc2213518257958", "Mihalkanin"),
    ("6a198b661218c31ab0f5ba4e", "Krizova"),
    ("6a19832b5fc221351825795e", "Stepek"),
    ("6a19832b5fc2213518257972", "Konecny"),
    ("6a1987481218c31ab0f5ba33", "Svoboda"),
    ("6a198b661218c31ab0f5ba42", "Kojecky"),
]


def main():
    apply = "--apply" in sys.argv
    client = MongoClient(MONGO_URI)
    col = client["feasibility"]["investigators"]

    print("=== NAHLED: predazeni STATUS radku ===\n")
    n = 0
    for inv_id, label in IDS:
        doc = col.find_one({"_id": ObjectId(inv_id)}, {"STATUS": 1})
        if not doc:
            print(f"!!! NENALEZEN {label} ({inv_id})")
            continue
        status = doc.get("STATUS", "") or ""
        if LINE in status:
            print(f"[SKIP] {label}: radek uz existuje")
            continue
        new_status = LINE + "\n" + status
        print(f"[OK]   {label}: + '{LINE}'")
        if apply:
            res = col.update_one({"_id": ObjectId(inv_id)}, {"$set": {"STATUS": new_status}})
            n += res.modified_count

    print()
    if apply:
        print(f">>> ZAPSANO: {n} zaznamu. Ted spust classify_krok_v1.0.py --apply")
    else:
        print(">>> DRY-RUN. Pro zapis spust s --apply")


if __name__ == "__main__":
    main()
