"""Finite synthetic GSC annotation-view review. No GSC access or writes."""
import json,pathlib,sys,datetime
def review(p):
    def done(status):return {'status':status,'annotationExistenceVerified':False,'propertyAccessVerified':False,'searchEffectEstablished':False,'writeApproved':False}
    if not isinstance(p,dict):return done('INPUT_UNRESOLVED')
    if not p.get('selectedProperty') or p.get('selectedProperty')!=p.get('recordProperty'):return done('PROPERTY_MISMATCH')
    if p.get('kind')!='custom':return done('ANNOTATION_KIND_REQUIRES_REVIEW')
    if p.get('role') not in {'owner','full','restricted'}:return done('ROLE_UNRESOLVED')
    if p.get('operation')=='edit':return done('EDIT_NOT_SUPPORTED')
    if p.get('operation') not in {'view','add'}:return done('OPERATION_UNRESOLVED')
    try:age=(datetime.date.fromisoformat(p['observedDay'])-datetime.date.fromisoformat(p['annotationDay'])).days
    except (KeyError,TypeError,ValueError):return done('DATE_UNRESOLVED')
    if age<0:return done('DATE_UNRESOLVED')
    if age>500:return done('OLDER_THAN_DOCUMENTED_RETENTION')
    if p['operation']=='add':
        if p['role']=='restricted':return done('ROLE_CANNOT_ADD')
        count=p.get('existingCount');note=p.get('note')
        if type(count) is not int or count<0 or not isinstance(note,str):return done('ADD_INPUT_UNRESOLVED')
        if count>=200:return done('DOCUMENTED_CAP_REACHED')
        if not note.strip() or len(note)>120:return done('NOTE_REQUIRES_REVIEW')
        if p.get('privacyReviewed') is not True:return done('PRIVACY_REVIEW_REQUIRED')
        return done('MANUAL_ADD_PREFLIGHT_ONLY')
    if p.get('view') in {'comparison','24hour'}:return done('EXPECTED_HIDDEN_BY_VIEW')
    if p.get('view')!='standard':return done('VIEW_UNRESOLVED')
    return done('STANDARD_VIEW_EXPECTATION_ONLY')
if __name__=='__main__':
    path=pathlib.Path(sys.argv[1])
    if path.stat().st_size>1048576:raise SystemExit('Input exceeds1MiB')
    print(json.dumps([{'case':x['case'],**review(x['packet'])} for x in json.loads(path.read_text())['cases']],ensure_ascii=False,indent=2))
