"""Validate an illustrative work event locally. No network calls or live execution."""
import json,sys
from pathlib import Path

def validate(event):
    if not isinstance(event,dict):return ['event must be an object']
    errors=[]
    for key in ['event_id','workspace_id','task_id','agent_id']:
        if not isinstance(event.get(key),str) or not event[key].strip():errors.append(key+' must be a nonempty string')
    if event.get('schema_version')!='0.1-example':errors.append('unsupported example schema version')
    if event.get('status') not in ['accepted','in_progress','blocked','submitted']:errors.append('unsupported example status')
    if event.get('status')=='submitted' and (not isinstance(event.get('evidence_refs'),list) or not event['evidence_refs'] or not all(isinstance(v,str) and v.strip() for v in event['evidence_refs'])):errors.append('submitted work needs evidence references')
    if event.get('sample_only') is not True:errors.append('this validator accepts sample events only')
    return errors

def main():
    if len(sys.argv)!=2:print('Usage: python3 flowise-event-validator.py sample.json');return 2
    try:
        path=Path(sys.argv[1])
        if path.stat().st_size>100000:raise ValueError('sample exceeds 100 KB')
        event=json.loads(path.read_text(encoding='utf-8'));errors=validate(event)
    except (OSError,ValueError) as exc:print(json.dumps({'validation':'FAIL','error':str(exc)}));return 1
    print(json.dumps({'validation':'FAIL' if errors else 'PASS','runtime':'local_contract_check_only','errors':errors,'network_requests':0}));return bool(errors)
if __name__=='__main__':sys.exit(main())
