import json, copy
from pathlib import Path
src = json.load(open('gen/data/ato/example-flight-academy.json'))
NOTE = "DEMO DATA ONLY. Made-up school, people, numbers and reviews. Not a real SACAA record."
out = Path('data'); out.mkdir(exist_ok=True)
for f in out.glob('*.json'): f.unlink()

# 1) Full school: paid, 2 bases, 3 certificates, 24 reviews
full = copy.deepcopy(src)
full.update(_note=NOTE, id="DEMO_0001_ATO", slug="demo-ato-alpha", name="Demo ATO Alpha", handle="demoatoalpha", status="paid")
full["bases"] = [
 {"ident":"FACT","name":"Cape Town International","town":"Cape Town","href":"/ad/FACT",
  "certificates":[{"number":"SACAA/0001/ATO","valid_until":"2027-06-30","updated":"2026-11-01"},
                  {"number":"SACAA/0002/ATO","valid_until":"2027-02-28","updated":"2026-11-01"}]},
 {"ident":"FAGG","name":"George","town":"George","href":"/ad/FAGG",
  "certificate":{"number":"SACAA/0003/ATO","valid_until":"2025-03-31","updated":"2026-11-01"}}]
full["about"] = "Demo text. A flight school on the general aviation side of the field, training private and commercial pilots on single- and twin-engine aircraft, with ground school in the evenings."
full["contact"] = {"phone":"+27 00 000 0000","email":"hello@demo.invalid","web":"demo.invalid"}
full["courses"] = ["Private Pilot Licence (A)","Commercial Pilot Licence (A)","Airline Transport Pilot Licence (A)",
  "Night rating","Instrument rating","Instructor rating, Grade III","Multi-engine class rating",
  "Type Rating – Aeroplanes certificated for operation with more than one pilot"]
r = full["rating"]; r.update(count=24, written=19, rated_hi=20, certificates=3, score="4.4",
  bars=[{"stars":5,"count":12},{"stars":4,"count":8},{"stars":3,"count":3},{"stars":2,"count":1},{"stars":1,"count":0}])
for c in r["categories"]: c["count"] = 24
revs = full["top_reviews"]
revs[0]["author"]={"name":"pilot.one","badges":[],"licences":["PPL"]}
revs[0]["official_replies"].append({"school":"demoatoalpha","paid":True,"own":True,"when":"2026-10-04","text":"Demo reply. Thank you. We send every student a written quote before the first lesson."})
for p in revs[0]["official_replies"]:
    if not p["own"]: p.update(school="demoatobravo", text="Demo reply from another school. This should not appear on this page.")
revs[1]["author"]={"name":"pilot.two","badges":["founding"],"licences":["CPL","Night"]}
revs[1]["official_replies"][0].update(school="demoatoalpha", text="Demo reply. Thank you. We added a second trainer to the summer roster from November.")
revs[1]["text"]="Ground school was the strongest part. Booking aircraft in summer took planning because the fleet is small."
full["visible_reviews"] = 19
json.dump(full, open(out/'demo-ato-alpha.json','w'), indent=1)

# 2) Under threshold: verified, 2 reviews, no score yet
two = json.load(open('gen/data/ato/example-air-school.json'))
two.update(_note=NOTE, id="DEMO_0002_ATO", slug="demo-ato-bravo", name="Demo ATO Bravo", handle="demoatobravo")
two["bases"][0]["certificate"]["number"]="SACAA/0004/ATO"
two["about"]="Demo text. A verified school that trains private pilots and night ratings on a small fleet of single-engine aircraft."
two["contact"]={"phone":"+27 00 000 0001","email":"hello@demo-b.invalid","web":"demo-b.invalid"}
two["top_reviews"][0]["author"]={"name":"pilot.three","badges":["dfe","founding"],"licences":["CPL","IR"]}
two["top_reviews"][1]["author"]={"name":"pilot.four","badges":[],"licences":["PPL"]}
json.dump(two, open(out/'demo-ato-bravo.json','w'), indent=1)

# 3) Empty, unclaimed
empty = {"_note":NOTE,"id":"DEMO_0003_ATO","slug":"demo-ato-charlie","name":"Demo ATO Charlie","status":"unclaimed",
 "bases":[{"ident":"FAWB","name":"Wonderboom","town":"Pretoria","href":"/ad/FAWB",
           "certificate":{"number":"SACAA/0005/ATO","valid_until":"2027-04-30","updated":"2026-10-28"}}],
 "about":"","contact":{},"courses":[],"rating":{"shown":False,"count":0,"written":0},"top_reviews":[],"visible_reviews":0}
json.dump(empty, open(out/'demo-ato-charlie.json','w'), indent=1)
print("ok")
