import pathlib,json,pcbnew,wx
app=wx.App(False);quiet=wx.LogNull()
p=pathlib.Path(__file__).resolve().parent
data=json.loads((p/'added-components.json').read_text()); contract=json.loads((p/'connection-contract.json').read_text())
rows=[]
for c in data:
 lib,item=c['footprint'].split(':')
 f=pcbnew.FootprintLoad('/Applications/KiCad/KiCad.app/Contents/SharedSupport/footprints/'+lib+'.pretty',item)
 assert f is not None,c['ref']
 nums={x.GetNumber() for x in f.Pads() if x.GetNumber()}
 assert nums==set(contract[c['ref']]),(c['ref'],nums,set(contract[c['ref']]))
 rows.append({'ref':c['ref'],'footprint':c['footprint'],'pad_numbers':sorted(nums)})
(p/'footprint-pad-check.json').write_text(json.dumps({'status':'ASSIGNED_FOOTPRINT_PAD_NUMBERS_PASS_NOT_DFM','parts':rows,'manufacturer_land_pattern_review':False,'pcb_created':False},indent=2)+'\n')
print('Assigned native footprint pad sets PASS:',len(rows))
