-- Medieval-style personal names for NPCs; generic elders/medics/stalls use per-id keys and pools (frontend/npcGeneratedNames.ts).

DO $$
DECLARE
elder_names text[] := ARRAY['Edmund Weaver','Roger Thane','Aldous Pryor','Wilfred Cantor','Benedict Marsh','Godwin Alder','Piers Roper','Simon Hext','Thaddeus Wexford','Lawrence Fitzhugh','Martin Crier','Humphrey Stowe','Geoffrey Merton','Richard Plowman','Walter Burgh','Thomas Reeve','Henry Wainwright','Stephen Tiler','Nicholas Cooper','James Fletcher']::text[];
medic_names text[] := ARRAY['Brother Anselm','Sister Gode','Brother Piers','Sister Edith','Brother Osmund','Sister Maud','Brother Cuthbert','Sister Agnes','Brother Wulfstan','Sister Hilde','Brother Leofric','Sister Elfrida','Brother Dunstan','Sister Godiva','Brother Aldwin','Sister Isolde','Brother Bertram','Sister Yvette','Brother Everard','Sister Matilda','Brother Hugh','Sister Beatrice','Brother Ralph','Sister Joan','Brother Miles','Sister Margery','Brother Guy','Sister Cecily','Brother Odo','Sister Ethelreda','Brother Fulke','Sister Rosamund','Brother Ivo','Sister Aveline','Brother Lambert','Sister Sybil','Brother Gerard','Sister Petronilla','Brother Thurstan','Sister Hawise']::text[];
stall_names text[] := ARRAY['Henric Cotlar','Giles Turner','Ralf Cordwainer','Drogo Mercer','Ivo Chapman','Baldwin Fuller','Reynard Webber','Sigeric Dyer','Ailwin Skinner','Leofwine Bowyer','Ordgar Fletcher','Wulfhere Smith','Eadric Mason','Cynric Thatcher','Beorn Carver','Grimwald Cooper','Sæward Potter','Tovi Weaver','Ketil Wright','Orm Gardiner','Hakon Fisher','Snorri Cook','Ulf Baker','Eirik Brewer','Halfdan Butcher','Ragnar Chandler','Sweyn Saddler','Toki Horner','Grim Kelner','Arnulf Spicer','Berenger Glover','Fulk Haberdasher','Payn Cutler','Jocelin Nailor','Eluard Whittler','Gervase Joiner','Hamo Sawyer','Isembard Planer','Lancelin Turner','Mainard Wheeler','Odo Carter','Pagan Porter','Quentin Badger','Roric Packer','Savin Binder','Turold Tenter','Ulric Shearer','Warin Fuller','Yvain Mercer','Zacharias Draper','Alured Hosier','Brien Leatherseller','Conan Fellmonger','Denzil Woolman','Elwin Silkman','Faramund Linendraper','Garin Mercer','Helias Chapman','Isembart Cordwainer','Jordan Webber','Kenelm Dyer','Laurin Skinner','Milo Bowyer','Nigel Fletcher','Osmund Smith','Percy Mason','Quince Thatcher','Roland Carver','Sayer Cooper','Turgis Potter','Urian Weaver','Virgil Wright','Wymar Gardiner','York Fisher','Zeno Cook','Alaric Baker','Brice Brewer','Crispin Butcher','Drust Chandler','Emeric Saddler','Faramir Horner','Gawain Kelner','Hadwin Spicer','Idris Glover','Jasper Haberdasher','Kenrick Cutler','Lionel Nailor','Merrick Whittler','Nestor Joiner','Owyn Sawyer','Piers Planer','Quinlan Turner','Roric Wheeler','Seward Carter','Tancred Porter','Ulfric Badger','Valens Packer','Wulfhere Binder','Yngvar Tenter','Zebulon Shearer','Athelstan Fuller','Baldric Mercer','Cerdic Chapman','Dunstan Cordwainer','Eadwine Webber','Frith Dyer','Godric Skinner','Hereward Bowyer','Ingulf Fletcher','Kenelm Smith','Leofric Mason','Mærwynn Thatcher']::text[];
BEGIN
  UPDATE public.npcs SET
    name_key = 'npc.elder.byid.' || id::text || '.v1',
    name = elder_names[1 + ((id * 3) % 20)]
  WHERE name_key = 'npc.town_speaker_generic.v1';

  UPDATE public.npcs SET
    name_key = 'npc.medic.byid.' || id::text || '.v1',
    name = medic_names[1 + ((id * 7) % 40)]
  WHERE name_key = 'npc.roadside_medic_generic.v1';

  UPDATE public.npcs SET
    name_key = 'npc.stall.byid.' || id::text || '.v1',
    name = stall_names[1 + ((id * 13) % 112)]
  WHERE name_key = 'npc.stall_vendor_generic.v1';
END $$;

UPDATE public.npcs SET name = v.n
FROM (VALUES
  ('npc.capital.merchant_clerk.v1', 'Hugh Pennington'),
  ('npc.capital.armorer.v1', 'Raoul d''Aubigny'),
  ('npc.capital.smith.v1', 'Gilles Ferron'),
  ('npc.capital.jeweler.v1', 'Ysabel Tremaine'),
  ('npc.capital.bounty_agent_a.v1', 'Roderick Vaughn'),
  ('npc.capital.bounty_agent_b.v1', 'Matteo Fabbri'),
  ('npc.capital.elder.v1', 'Anselm Corwyn'),
  ('npc.capital.healer.v1', 'Clothilde Mercier'),
  ('npc.capital.second_armorer.v1', 'Bertrand Hale'),
  ('npc.capital.second_jeweler.v1', 'Eleonore Rivard')
) AS v(k, n)
WHERE public.npcs.name_key = v.k;

UPDATE public.npcs SET name = CASE id
      WHEN 1 THEN 'Maren Thistlewood'
      WHEN 2 THEN 'Finn Marlow'
      WHEN 3 THEN 'Asha Kentwell'
      WHEN 4 THEN 'Halric Morrow'
      WHEN 5 THEN 'Wynn Cartwright'
      WHEN 6 THEN 'Orin Aldgate'
      WHEN 7 THEN 'Osbert Waynwood'
      WHEN 8 THEN 'Liora Selwyn'
    END
WHERE id BETWEEN 1 AND 8;

UPDATE public.npcs SET
  name_key = CASE id
      WHEN 9 THEN 'npc.brandric_thacker.v1'
      WHEN 10 THEN 'npc.conrad_pitwright.v1'
      WHEN 11 THEN 'npc.nessa_bramble.v1'
      WHEN 12 THEN 'npc.torin_marshwick.v1'
      WHEN 13 THEN 'npc.renulf_broadmere.v1'
      WHEN 14 THEN 'npc.kael_ironwright.v1'
      WHEN 15 THEN 'npc.edmund_cinderwell.v1'
      WHEN 16 THEN 'npc.aelith_northgate.v1'
      WHEN 17 THEN 'npc.dorian_hawke.v1'
      WHEN 18 THEN 'npc.mariel_starling.v1'
      WHEN 19 THEN 'npc.milo_ropewalk.v1'
      WHEN 20 THEN 'npc.lissa_harcourt.v1'
      WHEN 21 THEN 'npc.jasper_kindling.v1'
      WHEN 22 THEN 'npc.kess_wiley.v1'
      WHEN 23 THEN 'npc.aldwin_relicton.v1'
      WHEN 24 THEN 'npc.torvik_grimstad.v1'
      WHEN 25 THEN 'npc.morna_fenwick.v1'
      WHEN 26 THEN 'npc.morah_ellis.v1'
    END,
  name = CASE id
      WHEN 9 THEN 'Brandric Thacker'
      WHEN 10 THEN 'Conrad Pitwright'
      WHEN 11 THEN 'Nessa Bramble'
      WHEN 12 THEN 'Torin Marshwick'
      WHEN 13 THEN 'Renulf Broadmere'
      WHEN 14 THEN 'Kael Ironwright'
      WHEN 15 THEN 'Edmund Cinderwell'
      WHEN 16 THEN 'Aelith Northgate'
      WHEN 17 THEN 'Dorian Hawke'
      WHEN 18 THEN 'Mariel Starling'
      WHEN 19 THEN 'Milo Ropewalk'
      WHEN 20 THEN 'Lissa Harcourt'
      WHEN 21 THEN 'Jasper Kindling'
      WHEN 22 THEN 'Kess Wiley'
      WHEN 23 THEN 'Aldwin Relicton'
      WHEN 24 THEN 'Torvik Grimstad'
      WHEN 25 THEN 'Morna Fenwick'
      WHEN 26 THEN 'Morah Ellis'
    END
WHERE id BETWEEN 9 AND 26;


UPDATE public.npcs SET name = CASE id
      WHEN 27 THEN 'Sera Whitcomb'
      WHEN 28 THEN 'Bram Ashcombe'
      WHEN 29 THEN 'Nils Copperton'
      WHEN 30 THEN 'Mara Tinwell'
      WHEN 31 THEN 'Agnes Stillwater'
      WHEN 32 THEN 'Rodrick Cantrell'
      WHEN 33 THEN 'Wulfric Strand'
      WHEN 34 THEN 'Jada Boltwright'
      WHEN 35 THEN 'Alaric Motlow'
      WHEN 36 THEN 'Percival Pike'
      WHEN 37 THEN 'Eadric Ashenford'
      WHEN 38 THEN 'Yoric Scarn'
      WHEN 39 THEN 'Rillian Hereward'
      WHEN 40 THEN 'Tove Millerson'
      WHEN 41 THEN 'Gareth Grantham'
      WHEN 42 THEN 'Renulf Sackville'
      WHEN 43 THEN 'Bernard Lukin'
      WHEN 44 THEN 'Aldwin Grimston'
      WHEN 45 THEN 'Edmund Edgerton'
      WHEN 46 THEN 'Crispin Aylesford'
      WHEN 47 THEN 'Brunhild Flint'
      WHEN 48 THEN 'Oren Starward'
      WHEN 49 THEN 'Simon Spirewell'
      WHEN 50 THEN 'Hugh Comstock'
      WHEN 51 THEN 'Yves Portier'
      WHEN 52 THEN 'Cedric Brinewell'
      WHEN 53 THEN 'Osmund Salter'
      WHEN 54 THEN 'Rhys Reedman'
      WHEN 55 THEN 'Godfrey Middleton'
      WHEN 56 THEN 'Wystan Postlethwaite'
      WHEN 57 THEN 'Ivo Ironside'
      WHEN 58 THEN 'Roland Rivett'
      WHEN 59 THEN 'Lucan Forrest'
      WHEN 60 THEN 'Alaric Boghurst'
      WHEN 61 THEN 'Norbert Fenwick'
      WHEN 62 THEN 'Miles Myreham'
      WHEN 63 THEN 'Cuthbert Reed'
      WHEN 64 THEN 'Wendel Marsham'
      WHEN 65 THEN 'Sigurd Dunstan'
      WHEN 66 THEN 'Silas Siltwell'
      WHEN 67 THEN 'Peter Sanderson'
      WHEN 68 THEN 'Griselda Holt'
      WHEN 69 THEN 'Bartholomew Howe'
      WHEN 70 THEN 'Baldwin Bonewright'
      WHEN 71 THEN 'Cole Aldridge'
      WHEN 72 THEN 'Shadrach Morrow'
      WHEN 73 THEN 'Rowan Mistwell'
      WHEN 74 THEN 'Fergus Fogarty'
      WHEN 75 THEN 'Dewi Tarrant'
      WHEN 76 THEN 'Vespasian Vale'
      WHEN 77 THEN 'Hugo Holloway'
      WHEN 78 THEN 'Meredith Stowe'
      WHEN 79 THEN 'Roderick Rotherham'
      WHEN 80 THEN 'Beatrice Boghurst'
      WHEN 81 THEN 'Ashford Hale'
      WHEN 82 THEN 'Cyril Cinders'
      WHEN 83 THEN 'Emrys Emberly'
      WHEN 84 THEN 'Alicia Ashford'
      WHEN 85 THEN 'Thorne Hawthorn'
      WHEN 86 THEN 'Brian Briarton'
      WHEN 87 THEN 'Rowan Rootwell'
      WHEN 88 THEN 'Leofric Leaford'
      WHEN 89 THEN 'Galfrid Gales'
      WHEN 90 THEN 'Wynstan Windham'
      WHEN 91 THEN 'Gustav Merseburg'
      WHEN 92 THEN 'Blaise Brissot'
      WHEN 93 THEN 'Archibald Frostwick'
      WHEN 94 THEN 'Rhys Rimer'
      WHEN 95 THEN 'Horace Hoarwell'
      WHEN 96 THEN 'Isolde Ismay'
      WHEN 97 THEN 'Solomon Sunderland'
      WHEN 98 THEN 'Clifford Cliffeton'
      WHEN 99 THEN 'Craig Cragwell'
      WHEN 100 THEN 'Dustin Harwell'
      WHEN 101 THEN 'Marshall Fordham'
      WHEN 102 THEN 'Rivers Trent'
      WHEN 103 THEN 'Bridges Ballard'
      WHEN 104 THEN 'Sterling Brook'
      WHEN 105 THEN 'Sevrin Veilcourt'
      WHEN 106 THEN 'Sterling Starwell'
      WHEN 107 THEN 'Neville Nevett'
      WHEN 108 THEN 'Vera Veilhart'
    END
WHERE id BETWEEN 27 AND 108;
