"""Source/filesystem-only plan compiler. No DB, credentials, token, HTTP or native driver."""
from pathlib import Path
import json,hashlib
HERE=Path(__file__).resolve().parent
SOURCE=Path('/tmp/cdx-ai-final-weight-read-20261011/source')
READ=HERE.parent/'parallel-ai-api-customer-read12-20261011'
PINS=json.loads((READ/'source-frozen-sha.json').read_text())
relevant=['app/api/controller/user/UserWeight.php','app/api/service/user/UserWeight.php','app/api/model/User.php','app/common/model/User.php','app/api/service/User.php','app/api/model/staff/Staff.php','app/common/model/staff/Staff.php','app/common/Serve.php','app/common/UserApi.php','app/common/service/BaseService.php','app/common/model/user/Bind.php','app/common/model/user/UserWeight.php','app/common/model/user/UserWeightStatus.php','app/api/model/user/UserWeightStatus.php','app/common/model/user/UserScore.php','app/common/model/user/UserScoreLog.php','app/api/service/health/MetricProfileSync.php','app/api/service/health/MetricEvaluator.php','app/api/model/health/HealthMetricRecord.php','app/common/model/health/HealthMetricRecord.php','app/common/enum/health/MetricCode.php','app/api/service/health/Metric.php','app/api/controller/health/Archive.php','cores/BaseModel.php','cores/BaseController.php','vendor/topthink/think-orm/src/db/PDOConnection.php','vendor/topthink/think-orm/src/model/concern/TimeStamp.php','vendor/topthink/think-orm/src/model/concern/Conversion.php','vendor/topthink/framework/src/think/Request.php']
source={}
for n in relevant:
 digest=hashlib.sha256((SOURCE/n).read_bytes()).hexdigest();assert digest==PINS['files'][n];source[n]=digest
prep=[]
for lane in ['B','C']:
 marker=f'CDXWGT11_{lane}_U1'
 prep.append({'lane':lane,'AI.user':{'store_id':10001,'nick_name':marker,'mobile':'00000009992','gender':1,'avatar_id':0,'platform':'api','business':'zhct','channel':'10000','is_delete':0,'balance':'0.00','gift_balance':'0.00','pay_money':'0.00'},'AI.staff':{'user_id':'@NEW_AI_USER_ID','store_id':10001,'name':marker,'phone':'00000009992','gender':1,'birthday':'2000-01-01','height':'180.25','weight':'70.00','is_delete':0,'create_by':'CDXWGT11'},'identity':'Each table real auto ID; Staff.id is not assumed User.user_id','omitted_fields':'All actual physical columns/defaults/NULL/time from fresh metadata, exact fullrow retained','DML':{'INSERT':2,'UPDATE':0,'DELETE':0,'DDL':0}})
steps=[
 {'label':'W1_MANUAL','method':'POST','path':'/api/user.UserWeight/setWeight','body_raw':'{"form":{"weight":"72.34","height":"181.25","date":"2026-10-11"}}','INSERT':6,'UPDATE':1},
 {'label':'R1_MANUAL_ROWS','method':'GET','path':'/api/user.UserWeight/byDate','query_raw':'date=2026-10-11','INSERT':0,'UPDATE':0},
 {'label':'W2_GOAL','method':'POST','path':'/api/user.UserWeight/weightManage','body_raw':'{"form":{"initial_weight":72.5,"target_weight":"71.50","adjust_speed":2,"start_date":"2026-10-11"}}','INSERT':1,'UPDATE':2},
 {'label':'R2_GOAL_ROWS','method':'GET','path':'/api/user.UserWeight/byDate','query_raw':'date=2026-10-11','INSERT':0,'UPDATE':0},
 {'label':'R3_INFO','method':'GET','path':'/api/user.UserWeight/info','query_raw':'','INSERT':0,'UPDATE':0},
 {'label':'R4_GOAL_INFO','method':'GET','path':'/api/user.UserWeight/weightManageInfo','query_raw':'','INSERT':0,'UPDATE':0},
 {'label':'R5_STATUS_EXISTING_GOAL','method':'GET','path':'/api/user.UserWeight/status','query_raw':'','requires':'Actual own active goal exactly1; otherwise do not request hidden setter','INSERT':0,'UPDATE':0},
 {'label':'R6_DATES_NONEMPTY','method':'GET','path':'/api/user.UserWeight/dates','query_raw':'','INSERT':0,'UPDATE':0}]
writes={
 'W1_MANUAL':[
  {'table':'yoshop_user_weight','op':'INSERT','count':1,'fields':['user_id','store_id','date','weight','height','bmi','create_time','update_time'],'values':{'user_id':'@NEW_AI_USER_ID','store_id':10001,'date':1791648000,'weight':'72.34','height':181.25,'bmi':22.02,'create_time':'@time_integer','update_time':'@time_integer'}},
  {'table':'yoshop_staff','op':'UPDATE','count':1,'fields':['weight','@original_auto_update_time_if_source'],'where':'Actual source own Staff PK and tenant global scope; all original predicate/binds/types exact','values':{'weight':'@latest-own-weight-string72.34','height':'NOT_UPDATED'}},
  {'table':'yoshop_user_bind','op':'INSERT','count':1,'fields':['business','zhct_user_id','user_id','store_id','@original_auto_timestamps'],'values':{'business':'zhct','zhct_user_id':0,'user_id':'@NEW_AI_USER_ID','store_id':10001}},
  {'table':'yoshop_user_score_log','op':'INSERT','count':1,'fields':['user_id','store_id','type','meal_times','course','score','date','create_time','update_time'],'values':{'user_id':'@NEW_AI_USER_ID','store_id':10001,'type':1,'meal_times':0,'course':'','score':1,'date':'2026-10-11','create_time':'@time_integer','update_time':'@time_integer'}},
  {'table':'yoshop_user_score','op':'INSERT','count':1,'fields':['user_id','store_id','type','score','create_time','update_time'],'values':{'user_id':'@NEW_AI_USER_ID','store_id':10001,'type':1,'score':1,'create_time':'@time_integer','update_time':'@time_integer'}},
  {'table':'yoshop_user_health_metric_record','op':'INSERT','count':2,'phase':'after main commit; mandatory not hidden by catch','fields':['user_id','store_id','metric_code','value','secondary_value','unit','measure_date','measure_time','measure_site','source_type','source_key','evaluation_code','evaluation_name','evaluation_tone','disease_type','rule_version','is_delete','@original_auto_timestamps'],'values':{'metric_code':['weight','bmi'],'value':[72.34,22.02],'source_type':1,'source_key':'user-weight:@REAL_WEIGHT_ID','secondary_value':None,'unit':['kg',''],'measure_date':'2026-10-11','measure_time':'@source-current-HH:MM:SS','measure_site':'','evaluation_code':['recorded','normal'],'evaluation_name':['已记录','正常'],'evaluation_tone':['recorded','normal'],'disease_type':0,'rule_version':'v1','is_delete':0}}],
 'W2_GOAL':[
  {'table':'yoshop_user_weight_status','op':'INSERT','count':1,'fields':['user_id','store_id','start_date','initial_weight','target_weight','adjust_speed','status','end_date','@original_auto_timestamps'],'values':{'user_id':'@NEW_AI_USER_ID','store_id':10001,'start_date':1791648000,'initial_weight':72.5,'target_weight':'71.50','adjust_speed':2,'status':3,'end_date':1792771200}},
  {'table':'yoshop_user_weight','op':'UPDATE','count':1,'fields':['weight','height','bmi','update_time'],'where':'Exact original own weight PK / original scoped predicate','values':{'weight':72.5,'height':'180.25','bmi':22.31,'update_time':'@source_auto_integer'}},
  {'table':'yoshop_staff','op':'UPDATE','count':1,'fields':['weight','@original_auto_update_time_if_source'],'where':'Exact original own Staff PK / original scoped predicate','values':{'weight':'@latest-own-weight-string72.5','height':'NOT_UPDATED'}}]}
plan={'status':'SOURCE_ONLY_WAIT_ROOT_ACTIVITY_USER_HASH_WINDOW_CLOSE','DB':0,'SQL':0,'Auth':0,'HTTP_executed':0,'DMLDDL_executed':0,'source_HEAD':PINS['HEAD'],'full6168_manifest_reference':'../parallel-ai-api-customer-read12-20261011/source-frozen-sha.json','relevant_source_SHA':source,'prepare_rows_each_side':prep,'steps_each_side':steps,'native_write_scope':writes,'per_side_proposal':{'prepare_INSERT':2,'formal_HTTP':8,'formal_writers':2,'formal_readers':6,'formal_INSERT':7,'formal_UPDATE':3,'each_affected_max':1,'business_DELETE':0,'DDL':0,'external_HTTP':0,'real_queue':0,'own_token_max':1,'read_SQL_total_cap_proposed':1000,'preflight_read_cap_proposed':180},'boundaries':{'Serve':'Capture exact owned staffPower payload twice; no real Queue','UserApi':'Capture exact type1 params twice; is_success0/hs_order_id0/zhct_user_id0; original Bind0 insert real, no fake Store success','true_Store_loopback':'Required later separate real customer two-repo sync HTTP/database acceptance; source api_host and host_header support; not excluded as OSS/datacenter'},'hard_gates':['Actual date exactly2026-10-11 for same-day height branch','New actor marker/mobile0 collisions and own related rows all0','Existing9 table names proven only; fresh columns/defaults/FK/check/unique/identity before first prepare','Bind.zhct_user_id0 must be physically allowed or stop no value change','Full9table metadata/constructor warm at0HTTP','status only after actual valid goal1','W1 two health rows mandatory; any caught SQL failure partial failure, never replay committed W1','All previous actors13 and core0.01/0.02 ledger/state immutable','No loopback now, no Store4 fixture, no natural person/device/payment']}
(HERE/'machine-plan.json').write_text(json.dumps(plan,ensure_ascii=False,indent=2)+'\n')
print(json.dumps({'relevant_source_pins':len(source),'prepare_each_side':2,'proposed_HTTP_each':8,'formal_INSERT_each':7,'formal_UPDATE_each':3,'actual_DB':0,'actual_SQL':0,'actual_HTTP':0,'actual_Auth':0}))
