from models import Cluster,Network,Task
NETWORKS=[('R01','Survey & Technical Planning','A,B',['SSR validation','Technical proposal','Soil investigation','Coverage assessment']),('R02','Engineering & Drawings','B',['HLD/LLD','Structural design','PE endorsement']),('R03','Land & Site Acquisition','C',['Landowner verification','Tenancy','Site possession']),('R04','Authority & Permitting','C',['Authority submission','Permit approval']),('R05','Site Preparation','D,E',['Clearing and setting out','Earthworks','Platform preparation']),('R06','Foundation','F,G',['Piling or excavation','Reinforcement and formwork','Concrete casting','Foundation QA']),('R07','Tower Installation','H',['Tower supply','Tower erection','Alignment and bolt tests']),('R08','Power Infrastructure','J,K',['Power design','Grid or solar installation','Power tests']),('R09','Earthing & Lightning','I',['Earthing installation','Lightning protection','Resistance test']),('R10','Civil & Ancillary','K,L,M,N,O',['Fencing and gate','Drainage','Access road','Ducting']),('R11','Safety & Site Systems','P',['Fire protection','Aviation lights','Compound lighting']),('R12','Quality & Inspection','A,R',['Material QA','Site inspection','Defect closure']),('R13','Project Management','Q',['Programme and milestone','Contractor coordination','Progress reporting']),('R14','Documentation & Handover','R',['As-built documents','PAC checklist','FAC closure','Asset register'])]
def seed(db):
 for n in range(10,15):
  if not db.query(Cluster).filter_by(code=f'C{n}').first():db.add(Cluster(code=f'C{n}',name=f'Cluster {n}'))
 db.flush()
 for code,name,ref,tasks in NETWORKS:
  net=db.query(Network).filter_by(code=code).first()
  if not net:net=Network(code=code,name=name,boq_reference=ref);db.add(net);db.flush()
  for title in tasks:
   if not db.query(Task).filter_by(network_id=net.id,title=title).first():db.add(Task(network_id=net.id,title=title))
 db.commit()
