"""Apply the real right-pan/left-edit shortcut checks to fresh round7 tasks."""
from pathlib import Path
import sys
import types

PROJECT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(PROJECT));sys.path.insert(0,str(PROJECT/'scripts'))
from pallet.mask_model_training_data import require,write
from pallet.cluster_targets import digest
from pallet.pallet_description_round7_release import RELEASE
from serve_pallet_description_round7 import gallery,TriageHandler


def check(mode):
    path=PROJECT/'scripts/check_pallet_review_save_complete_pointer.py';source=path.read_text()
    anchor="snapshot_db(RELEASE/mode/'before.sqlite3',directory/'mask_reviews.sqlite3');"
    require(source.count(anchor)==1,'Pointer snapshot anchor changed');source=source.replace(anchor,'')
    source=source.replace("for mode in ('new','existing'):",'for mode in (requested_mode,):')
    source=source.replace("RELEASE/'pointer_verification.json'","RELEASE/requested_mode/'pointer_verification.json'")
    source=source.replace("RELEASE/f'pointer_failure_","RELEASE/requested_mode/f'pointer_failure_")
    module=types.ModuleType('_round7_pointer');module.__file__=str(path);exec(compile(source,str(path),'exec'),module.__dict__)
    module.RELEASE=RELEASE;module.gallery=gallery;module.ExistingHandler=TriageHandler;module.requested_mode=mode
    (RELEASE/mode/'checks/adapted_pointer.py').write_text(source);module.check()
    write(RELEASE/mode/'checks/pointer_adapter.json',dict(adapter_sha256=digest(Path(__file__)),source_sha256=digest(path),adapted_sha256=digest(RELEASE/mode/'checks/adapted_pointer.py'),production_annotation_POSTs=0))


if __name__=='__main__':
    import argparse
    p=argparse.ArgumentParser();p.add_argument('mode',choices=('new','existing'));a=p.parse_args();check(a.mode)
