#!/usr/bin/env python3
"""Bank batch-133: plants, trees, bark, leaves, roots, vines, and plant materials.

Rows are hand-authored in the main loop from dictionary flora entries and Patz
plant-part / bark / fruit examples. The script only stores the rows.
"""

from __future__ import annotations

import datetime as dt
import json
import re
import sqlite3
import sys

DB = "/mnt/donto-data/donto-resources/research/translation-training/kuku-yalanji-runpod-2026-06-30/synthetic/claude-synthetic-v1-2026-07-02/synthetic.db"
LABEL = "batch-133"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")

DENY = {
    "nyawa", "jinbi", "jibin", "walba", "julmbu", "wanan", "ngampula",
    "yalama", "ngana-jinji", "jubuny", "wural", "bigan", "jiwuny",
    "warngkul", "wanaba", "jarrkunji", "munjal", "murku", "buni",
    "kunya", "milkan", "kulur-jambul", "janyji", "buburr", "jarrmba",
    "jinji", "daga", "wanka", "yumbul", "kuku-yumbul", "jubi",
    "yilbay", "jarrakay", "janka-yukil", "jukarr", "kunkul",
    "bubu-jandu", "bubu-warral", "jani-warra", "balbay-nja",
    "bunjurril", "buri",
}


def js(values: list[str]) -> str:
    return json.dumps(values, ensure_ascii=False)


ROWS = [
    (1, "The leaves on the tree are very big.",
     "Birra juku-ngu yalbay-bajaku.",
     "birra juku-ngu yalbay-baja-ku | leaf tree-LOC big-DEG-EMPH",
     "plant_part_locative_attested", 5, js(["birra", "juku", "yalbay", "-bajaku"]), js([]),
     "Patz ex.524: birra juku-ngu yalbay-bajaku; locative = leaves on the tree.", "0.90"),
    (2, "The leaves from the tree are very big.",
     "Birra juku-muny yalbay-bajaku.",
     "birra juku-muny yalbay-baja-ku | leaf tree-ABL big-DEG-EMPH",
     "plant_part_ablative_attested", 5, js(["birra", "juku", "yalbay", "-bajaku"]), js([]),
     "Patz ex.524 contrasts juku-ngu and juku-muny for leaves on/from the tree.", "0.90"),
    (3, "The fruit on that tree is good.",
     "Mayi yinya-nga juku-ngu ngulkurr.",
     "mayi yinya-nga juku-ngu ngulkurr | fruit that-LOC tree-LOC good",
     "plant_fruit_locative_attested", 5, js(["mayi", "yinya", "juku", "ngulkurr"]), js([]),
     "Controlled from Patz ex.525 fruit on that tree is good to eat; avoids risky nuka-ji-y surface.", "0.88"),
    (4, "The fruit from that tree is good.",
     "Mayi yinya-muny juku-muny ngulkurr.",
     "mayi yinya-muny juku-muny ngulkurr | fruit that-ABL tree-ABL good",
     "plant_fruit_ablative_attested", 5, js(["mayi", "yinya", "juku", "ngulkurr"]), js([]),
     "Patz ex.525 allows ablative for fruit from that tree.", "0.88"),
    (5, "There are many branches on the tree.",
     "Dakil juku-ngu wubul.",
     "dakil juku-ngu wubul | branch tree-LOC many",
     "plant_branch_locative", 4, js(["dakil", "juku", "wubul"]), js([]),
     "Dictionary dakil = arm/branch/wing; locative tree part frame controlled by ex.524.", "0.84"),
    (6, "Branches fell from the tree.",
     "Dakil-dakil juku-muny daran.",
     "dakil-dakil juku-muny dara-ny | branch-REDUP tree-ABL fall-PAST",
     "plant_branch_ablative_motion", 4, js(["dakil-dakil", "juku", "daray"]), js([]),
     "Dictionary dakil-dakil branches; ablative source from ex.524.", "0.84"),
    (7, "There are many flowers on the tree.",
     "Nganka juku-ngu wubul.",
     "nganka juku-ngu wubul | flower tree-LOC many",
     "plant_flower_locative", 4, js(["nganka", "juku", "wubul"]), js([]),
     "Dictionary nganka = flower/blossom; tree locative pattern from Patz.", "0.84"),
    (8, "Seeds fell from the tree.",
     "Diburr juku-muny daran.",
     "diburr juku-muny dara-ny | seed tree-ABL fall-PAST",
     "plant_seed_ablative_motion", 4, js(["diburr", "juku", "daray"]), js([]),
     "Dictionary diburr = seed/egg; plant sense logged here by tree-source frame.", "0.84"),
    (9, "The tree roots are down below.",
     "Ngara juku-ngu badabada.",
     "ngara juku-ngu badabada | root tree-LOC down.below",
     "plant_root_locative", 4, js(["ngara", "juku", "badabada"]), js([]),
     "Dictionary ngara = root; badabada location word from Rule 85.", "0.83"),
    (10, "The base of the tree is big.",
     "Dingal juku-ngu yalbay.",
     "dingal juku-ngu yalbay | tree.base tree-LOC big",
     "plant_tree_base", 4, js(["dingal", "juku", "yalbay"]), js([]),
     "Dictionary dingal = base of a tree.", "0.84"),
    (11, "There is a hollow trunk in the tree.",
     "Dimbir juku-ngu.",
     "dimbir juku-ngu | hollow.trunk tree-LOC",
     "plant_hollow_trunk", 4, js(["dimbir", "juku"]), js([]),
     "Dictionary dimbir = hollow trunk of a tree.", "0.84"),
    (12, "The bark on the tree is hard.",
     "Dumbul juku-ngu dandi.",
     "dumbul juku-ngu dandi | bark tree-LOC hard",
     "plant_bark_locative", 5, js(["dumbul", "juku", "dandi"]), js([]),
     "Patz ex.526 licenses dumbul as hard covering; dictionary dumbul = bark/crust/shell.", "0.88"),
    (13, "Bark fell from the tree.",
     "Dumbul juku-muny daran.",
     "dumbul juku-muny dara-ny | bark tree-ABL fall-PAST",
     "plant_bark_ablative_motion", 4, js(["dumbul", "juku", "daray"]), js([]),
     "Uses the ex.524 ablative part-from-tree frame.", "0.84"),
    (14, "The two were sitting in the tree top.",
     "Bula jalban-ba bundandan.",
     "bula jalban-ba bunda-nda-ny | they.two tree.top-LOC sit-REDUP-PAST",
     "plant_tree_top_attested", 5, js(["bula", "jalban", "bunday"]), js([]),
     "Patz text 51 line 25 has tree-top locative jalban-ba with sitting.", "0.88"),
    (15, "The child climbs on the tree.",
     "Karrkay juku-ngu dakal.",
     "karrkay juku-ngu daka-l | child tree-LOC climb-NONPAST",
     "plant_tree_climb", 5, js(["karrkay", "juku", "dakal"]), js([]),
     "Controlled from text 51 line 11 ngali juku-ngu daka-l.", "0.86"),

    (16, "The two went to the river and found Leichhardt-tree fruit.",
     "Bula wawubaja-nga dungan, bula mayi kabal warrmba-bungan.",
     "bula wawubaja-nga dunga-ny, bula mayi kabal warrmba-bunga-ny | they.two river-LOC go-PAST they.two fruit Leichhardt.tree uncover-CAUS-PAST",
     "plant_fruit_text51_finding", 5, js(["bula", "wawubaja", "dungay", "mayi", "kabal", "warrmba-bungal"]), js([]),
     "Patz text 51 lines 6-7: the two find kabal fruit.", "0.90"),
    (17, "They found Leichhardt-tree fruit.",
     "Kabal mayi warrmba-bungan.",
     "kabal mayi warrmba-bunga-ny | Leichhardt.tree fruit uncover-CAUS-PAST",
     "plant_fruit_text51_reprise", 5, js(["kabal", "mayi", "warrmba-bungal"]), js([]),
     "Patz text 51 line 7 reprise: Kabal mayi warrmba-bunga-ny.", "0.90"),
    (18, "We two will climb on the tree.",
     "Ngali juku-ngu dakal.",
     "ngali juku-ngu daka-l | we.two.incl tree-LOC climb-NONPAST",
     "plant_tree_climb_attested", 5, js(["ngali", "juku", "dakal"]), js([]),
     "Patz text 51 line 11: Ngali juku-ngu daka-l.", "0.90"),
    (19, "The two climbed the tree.",
     "Bula juku-ngu dakan.",
     "bula juku-ngu daka-ny | they.two tree-LOC climb-PAST",
     "plant_tree_climb_past", 4, js(["bula", "juku", "dakal"]), js([]),
     "Controlled from text 51 line 12 Bula daka-ny plus explicit tree locative.", "0.86"),
    (20, "They climbed, kept taking fruit from the tree and eating it.",
     "Dakan, juku-muny manil-manin mayi nukal-nukan.",
     "daka-ny, juku-muny mani-l-mani-ny mayi nuka-l-nuka-ny | climb-PAST tree-ABL get-l-REDUP-PAST fruit eat-l-REDUP-PAST",
     "plant_fruit_text51_redup_sequence", 5, js(["dakal", "juku", "manil", "mayi", "nukal"]), js([]),
     "Patz text 51 line 13: taking fruit from tree and eating repeatedly.", "0.90"),
    (21, "Fruit fell from the tree.",
     "Mayi juku-muny daran.",
     "mayi juku-muny dara-ny | fruit tree-ABL fall-PAST",
     "plant_fruit_fall", 4, js(["mayi", "juku", "daray"]), js([]),
     "ABL source-from-tree frame with fruit.", "0.84"),
    (22, "The child got fruit from the tree.",
     "Karrkay-ngku mayi juku-muny manin.",
     "karrkay-ngku mayi juku-muny mani-ny | child-ERG fruit tree-ABL get-PAST",
     "plant_fruit_get_from_tree", 4, js(["karrkay", "mayi", "juku", "manil"]), js([]),
     "Controlled fruit-from-tree transitive frame.", "0.84"),
    (23, "They ate fruit from the tree.",
     "Jana mayi juku-muny nukan.",
     "jana mayi juku-muny nuka-ny | they fruit tree-ABL eat-PAST",
     "plant_fruit_eat_from_tree", 4, js(["jana", "mayi", "juku", "nukal"]), js([]),
     "Simple fruit-source eating frame.", "0.84"),
    (24, "A tree with many big leaves stands there.",
     "Juku birra-jirr jabajaba-jirr yinyay janjanay.",
     "juku birra-jirr jabajaba-jirr yinyay janja-na-y | tree leaf-COMIT plentiful-COMIT there stand-REDUP-NONPAST",
     "plant_comitative_leafy_tree", 5, js(["juku", "birra", "jabajaba", "yinyay", "janjanay"]), js([]),
     "Controlled from Patz ex.544 juku-ku birra-jirr-ka jabajaba-jirr-ka.", "0.86"),
    (25, "He came from that house with the tree.",
     "Nyulu bayan-muny yinya-muny juku-jirr-muny kadan.",
     "nyulu bayan-muny yinya-muny juku-jirr-muny kada-ny | he house-ABL that-ABL tree-COMIT-ABL come-PAST",
     "plant_comitative_ablative_attested", 5, js(["nyulu", "bayan", "yinya", "juku", "kaday"]), js([]),
     "Patz ex.546: came from that house with the tree.", "0.90"),

    (26, "Long ago they chopped bark.",
     "Ngadiku jana dubal nyandan.",
     "ngadiku jana dubal nyanda-ny | long.ago they bark chop-PAST",
     "plant_bark_text51_chop", 5, js(["ngadiku", "jana", "dubal", "nyandal"]), js([]),
     "Patz text 51 line 61: old-time bark chopping.", "0.90"),
    (27, "They poured water into the bark.",
     "Bana nyangarrin dubal-ba.",
     "bana nyangarri-ny dubal-ba | water pour-PAST bark-LOC",
     "plant_bark_text51_pour", 5, js(["bana", "nyangarril", "dubal"]), js([]),
     "Patz text 51 line 63: bana nyangarri-nya dubal-ba.", "0.90"),
    (28, "Paperbark sat on top of the meat.",
     "Buyku minya wangkar bundandan.",
     "buyku minya wangkar bunda-nda-ny | paperbark meat above sit-REDUP-PAST",
     "plant_paperbark_cover", 5, js(["buyku", "minya", "wangkar", "bunday"]), js([]),
     "Controlled from Patz text 51 line 66: buyku bundanda-nya covering the meat.", "0.86"),
    (29, "They put paperbark in the ground oven.",
     "Jana buyku kurrma-nga yijarrin.",
     "jana buyku kurrma-nga yijarri-ny | they paperbark ground.oven-LOC put-PAST",
     "plant_paperbark_oven", 4, js(["jana", "buyku", "kurrma", "yijarril"]), js([]),
     "Controlled earth-oven frame from text 51 and Rule 83.", "0.84"),
    (30, "They put ti-tree bark on the house.",
     "Jana wanjakan dumbul bayan-ba yijarrin.",
     "jana wanjakan dumbul bayan-ba yijarri-ny | they ti.tree bark house-LOC put-PAST",
     "plant_titree_bark_roof", 4, js(["jana", "wanjakan", "dumbul", "bayan", "yijarril"]), js([]),
     "Dictionary wanjakan bark used for roof of house; simple put-on-house frame.", "0.84"),
    (31, "They made a net with tree bark.",
     "Jana warrur-bu makarr bungan.",
     "jana warrur-bu makarr bunga-ny | they tree.bark-INST net make-PAST",
     "plant_bark_fishnet_material", 4, js(["jana", "warrur", "makarr", "bungal"]), js([]),
     "Dictionary warrur: tree bark used to make fishnets.", "0.84"),
    (32, "A sapling stands near the camp.",
     "Jaba bayan ngundu-ba janjanay.",
     "jaba bayan ngundu-ba janja-na-y | sapling camp close-LOC stand-REDUP-NONPAST",
     "plant_sapling_stands", 4, js(["jaba", "bayan", "ngundu", "janjanay"]), js([]),
     "Dictionary jaba = stick/sapling/post/walking stick.", "0.84"),
    (33, "The child dug the ground with a stick.",
     "Karrkay-ngku jaba-bu bubu bakan.",
     "karrkay-ngku jaba-bu bubu baka-ny | child-ERG stick-INST ground dig-PAST",
     "plant_stick_instrument", 4, js(["karrkay", "jaba", "bubu", "bakal"]), js([]),
     "Instrumental plant-material frame; baka-l dig/poke from Rule 71.", "0.84"),
    (34, "Burn ironwood bark lest thunder come.",
     "Jujabala dumbul waju, jarramali kada-nyji.",
     "jujabala dumbul waju, jarramali kada-nyji | ironwood bark burn.IMP thunder come-PRECAUT",
     "plant_ironwood_thunder_control", 5, js(["jujabala", "dumbul", "wajul", "jarramali", "kaday", "-nyji"]), js([]),
     "Dictionary jujabala notes bark burned to control thunder; Patz weather precaution frame.", "0.88"),
    (35, "Burn grass tree lest thunder come.",
     "Nganjirr waju, jarramali kada-nyji.",
     "nganjirr waju, jarramali kada-nyji | grass.tree burn.IMP thunder come-PRECAUT",
     "plant_grasstree_thunder_control", 5, js(["nganjirr", "wajul", "jarramali", "kaday", "-nyji"]), js([]),
     "Dictionary nganjirr notes burning grass tree to make thunder go away.", "0.88"),

    (36, "The lawyer-cane vine stands in the scrub.",
     "Mawar madja-nga janjanay.",
     "mawar madja-nga janja-na-y | lawyer.cane.vine scrub-LOC stand-REDUP-NONPAST",
     "plant_vine_scrub", 4, js(["mawar", "madja", "janjanay"]), js([]),
     "Dictionary mawar = lawyer-cane vine; madja = scrub/rainforest.", "0.84"),
    (37, "The stinging vine stands in the scrub.",
     "Waji-waji madja-nga janjanay.",
     "waji-waji madja-nga janja-na-y | stinging.vine scrub-LOC stand-REDUP-NONPAST",
     "plant_stinging_vine_scrub", 4, js(["waji-waji", "madja", "janjanay"]), js([]),
     "Dictionary waji-waji = stinging vine.", "0.84"),
    (38, "The palm stands in the scrub.",
     "Kunjarri madja-nga janjanay.",
     "kunjarri madja-nga janja-na-y | palm scrub-LOC stand-REDUP-NONPAST",
     "plant_palm_scrub", 4, js(["kunjarri", "madja", "janjanay"]), js([]),
     "Dictionary kunjarri = palm/palm tree.", "0.84"),
    (39, "Black palm is a big tree.",
     "Duwar juku yalbay.",
     "duwar juku yalbay | black.palm tree big",
     "plant_black_palm", 4, js(["duwar", "juku", "yalbay"]), js([]),
     "Dictionary duwar = black palm.", "0.84"),
    (40, "The umbrella palm stands by the river.",
     "Dulmbil wawubaja-nga janjanay.",
     "dulmbil wawubaja-nga janja-na-y | umbrella.palm river-LOC stand-REDUP-NONPAST",
     "plant_umbrella_palm_river", 4, js(["dulmbil", "wawubaja", "janjanay"]), js([]),
     "Dictionary dulmbil = umbrella palm.", "0.84"),
    (41, "The cottontree has big flowers.",
     "Wawuburra nganka yalbay.",
     "wawuburra nganka yalbay | cottontree flower big",
     "plant_cottontree_flower", 4, js(["wawuburra", "nganka", "yalbay"]), js([]),
     "Dictionary wawuburra notes big red flowers; color avoided, flower size retained.", "0.84"),
    (42, "They made a canoe from cottontree.",
     "Jana wawuburra-muny buwun bungan.",
     "jana wawuburra-muny buwun bunga-ny | they cottontree-ABL boat make-PAST",
     "plant_cottontree_canoe", 4, js(["jana", "wawuburra", "buwun", "bungal"]), js([]),
     "Dictionary wawuburra notes canoes made from this tree.", "0.84"),
    (43, "They made a canoe from candlenut tree.",
     "Jana bilar-muny buwun bungan.",
     "jana bilar-muny buwun bunga-ny | they candlenut.tree-ABL boat make-PAST",
     "plant_candlenut_canoe", 4, js(["jana", "bilar", "buwun", "bungal"]), js([]),
     "Dictionary wawuburra entry notes canoes made from wawuburra and bilar.", "0.84"),
    (44, "The black wattle has flowers.",
     "Yarun nganka-ji.",
     "yarun nganka-ji | black.wattle flower-COMIT",
     "plant_wattle_flower", 4, js(["yarun", "nganka", "-ji"]), js([]),
     "Dictionary yarun = black wattle tree and its yellow flower; color not asserted in Kuku row.", "0.84"),
    (45, "The white wattle tree stands there.",
     "Yalngkal yinyay janjanay.",
     "yalngkal yinyay janja-na-y | white.wattle there stand-REDUP-NONPAST",
     "plant_white_wattle", 4, js(["yalngkal", "yinyay", "janjanay"]), js([]),
     "Dictionary yalngkal = white wattle.", "0.84"),
    (46, "The bottlebrush tree has many flowers.",
     "Yumu nganka wubul.",
     "yumu nganka wubul | bottlebrush flower many",
     "plant_bottlebrush_flower", 4, js(["yumu", "nganka", "wubul"]), js([]),
     "Dictionary yumu = bottlebrush tree.", "0.84"),
    (47, "Ti-tree bark is on the house.",
     "Wanjakan dumbul bayan-ba.",
     "wanjakan dumbul bayan-ba | ti.tree bark house-LOC",
     "plant_titree_bark_house", 4, js(["wanjakan", "dumbul", "bayan"]), js([]),
     "Dictionary wanjakan says bark used for roofs; locative house frame.", "0.84"),
    (48, "Tree bark is like rope.",
     "Warrur yala karra.",
     "warrur yala karra | tree.bark like rope/string",
     "plant_bark_vine_rope", 4, js(["warrur", "yala", "karra"]), js([]),
     "Dictionary warrur: tree bark can be used as vine; karra = string/rope.", "0.84"),
    (49, "The tree with leaves stands there.",
     "Juku birra-jirr yinyay janjanay.",
     "juku birra-jirr yinyay janja-na-y | tree leaf-COMIT there stand-REDUP-NONPAST",
     "plant_leaf_comitative", 4, js(["juku", "birra", "yinyay", "janjanay"]), js([]),
     "Comitative leaf frame controlled from Patz ex.544.", "0.84"),
    (50, "The flowers fell from the tree.",
     "Nganka juku-muny daran.",
     "nganka juku-muny dara-ny | flower tree-ABL fall-PAST",
     "plant_flower_ablative_motion", 4, js(["nganka", "juku", "daray"]), js([]),
     "Completes plant-part source frame with flowers from tree.", "0.84"),
]


def scan_static() -> list[str]:
    issues: list[str] = []
    if len(ROWS) != 50:
        issues.append(f"expected 50 rows, got {len(ROWS)}")
    seqs = [r[0] for r in ROWS]
    if seqs != list(range(1, 51)):
        issues.append(f"seqs must be 1..50, got {seqs[:5]}...{seqs[-5:]}")
    seen_ku: set[str] = set()
    for row in ROWS:
        seq, english, kuku, analysis, _frame, _tier, words_used, loans_used, _evidence, _confidence = row
        label = f"{LABEL}.{seq:02d}"
        if not english[:1].isupper() or english.rstrip("'\"").rstrip()[-1:] not in ".!?":
            issues.append(f"{label}: English must be capitalized and final-punctuated")
        if " | " not in analysis:
            issues.append(f"{label}: analysis missing gloss separator")
        if not kuku[:1].isupper():
            issues.append(f"{label}: Kuku surface must start uppercase")
        for field_name, payload in (("words_used", words_used), ("loans_used", loans_used)):
            try:
                json.loads(payload)
            except Exception as exc:
                issues.append(f"{label}: {field_name} is not JSON: {exc}")
        low = f" {kuku.lower()} {analysis.lower()} "
        for word in DENY:
            if re.search(rf"(?<![a-z]){re.escape(word)}(?![a-z])", low):
                issues.append(f"{label}: denied phantom/wrong-sense token {word!r}")
        if kuku.lower() in seen_ku:
            issues.append(f"{label}: duplicate Kuku surface within batch")
        seen_ku.add(kuku.lower())
    return issues


def main() -> int:
    issues = scan_static()
    if issues:
        print("pre-bank scan failed:")
        for issue in issues:
            print(f"  - {issue}")
        return 1

    db = sqlite3.connect(DB)
    db.execute("PRAGMA foreign_keys = ON")
    db.execute("BEGIN")
    existing = db.execute("SELECT id FROM batches WHERE label=?", (LABEL,)).fetchone()
    if existing:
        batch_id = existing[0]
        accepted = db.execute(
            "SELECT COUNT(*) FROM sentences WHERE batch_id=? AND status IN ('accepted','revised')",
            (batch_id,),
        ).fetchone()[0]
        if accepted:
            raise SystemExit(f"{LABEL} already has accepted/revised rows; refusing to overwrite")
        db.execute("DELETE FROM reviews WHERE sentence_id IN (SELECT id FROM sentences WHERE batch_id=?)", (batch_id,))
        db.execute("DELETE FROM sentences WHERE batch_id=?", (batch_id,))
        db.execute("UPDATE batches SET notes=?, created_at=? WHERE id=?", ("rebanked under_review", NOW, batch_id))
    else:
        cur = db.execute(
            "INSERT INTO batches(label, cheatsheet_version, guide_version, notes, created_at) VALUES(?,?,?,?,?)",
            (LABEL, "Rule 91 draft: plants, trees, and plant materials", "operator-guide-2026-07-07", "under_review", NOW),
        )
        batch_id = cur.lastrowid

    dupes = []
    for seq, _english, kuku, *_rest in ROWS:
        hit = db.execute(
            """
            SELECT b.label, s.seq
            FROM sentences s JOIN batches b ON b.id=s.batch_id
            WHERE lower(trim(s.kuku))=lower(trim(?))
              AND s.status!='rejected'
              AND s.batch_id!=?
            """,
            (kuku, batch_id),
        ).fetchone()
        if hit:
            dupes.append(f"{LABEL}.{seq:02d} duplicates {hit[0]}.{hit[1]:02d}: {kuku}")
    if dupes:
        db.rollback()
        print("cross-corpus duplicate check failed:")
        for dupe in dupes:
            print(f"  - {dupe}")
        return 1

    db.executemany(
        """
        INSERT INTO sentences(
            batch_id, seq, english, kuku, analysis, frame, tier, words_used,
            loans_used, evidence, status, confidence, rights_status, author,
            created_at, updated_at
        ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
        """,
        [
            (
                batch_id, seq, english, kuku, analysis, frame, tier, words_used,
                loans_used, evidence, "under_review", confidence,
                "project_approved_synthetic_pending_elder_verification",
                "claude-main", NOW, NOW,
            )
            for seq, english, kuku, analysis, frame, tier, words_used, loans_used, evidence, confidence in ROWS
        ],
    )
    db.commit()
    count = db.execute("SELECT COUNT(*) FROM sentences WHERE batch_id=?", (batch_id,)).fetchone()[0]
    avg_words = db.execute(
        "SELECT AVG(LENGTH(kuku)-LENGTH(REPLACE(kuku,' ',''))+1.0) FROM sentences WHERE batch_id=?",
        (batch_id,),
    ).fetchone()[0]
    print(f"banked {LABEL}: {count} rows under_review; avg Kuku words/row={avg_words:.2f}")
    return 0


if __name__ == "__main__":
    sys.exit(main())
