INSERT INTO worlds (name,slug,status,world_time,settings_json)
VALUES ('EVO House','evo-house','active',UTC_TIMESTAMP(),JSON_OBJECT('timezone','UTC','simulation_version','0.1'))
ON DUPLICATE KEY UPDATE name=VALUES(name);

INSERT INTO world_state (world_id,tick_count,last_tick_at,state_json)
SELECT id,0,UTC_TIMESTAMP(),JSON_OBJECT('day',1,'weather','clear')
FROM worlds WHERE slug='evo-house'
ON DUPLICATE KEY UPDATE world_id=VALUES(world_id);

INSERT INTO agents (world_id,name,model_key,status,personality_json,needs_json,position_json,current_action)
SELECT w.id, a.name, a.model_key, 'active',
       a.personality, JSON_OBJECT('energy',100,'hunger',0,'health',100,'curiosity',70,'social',50),
       a.position, 'observing'
FROM worlds w
JOIN (
  SELECT 'Milo' name,'robot_milo' model_key,
    JSON_OBJECT('curiosity',85,'sociability',65,'caution',35) personality,
    JSON_OBJECT('x',-2.5,'y',0,'z',-1.5) position
  UNION ALL SELECT 'Nova','robot_nova',JSON_OBJECT('curiosity',70,'sociability',85,'caution',30),JSON_OBJECT('x',-1.2,'y',0,'z',1.5)
  UNION ALL SELECT 'Pip','robot_pip',JSON_OBJECT('curiosity',95,'sociability',55,'caution',20),JSON_OBJECT('x',1.3,'y',0,'z',-1.2)
  UNION ALL SELECT 'Kiro','robot_kiro',JSON_OBJECT('curiosity',55,'sociability',75,'caution',70),JSON_OBJECT('x',2.5,'y',0,'z',1.4)
  UNION ALL SELECT 'Zuri','robot_zuri',JSON_OBJECT('curiosity',75,'sociability',60,'caution',50),JSON_OBJECT('x',0,'y',0,'z',2.6)
) a
WHERE w.slug='evo-house'
AND NOT EXISTS (SELECT 1 FROM agents existing WHERE existing.world_id=w.id AND existing.model_key=a.model_key);

INSERT INTO world_resources (world_id,resource_key,quantity,unit)
SELECT id,'wood',20,'unit' FROM worlds WHERE slug='evo-house'
ON DUPLICATE KEY UPDATE resource_key=VALUES(resource_key);
INSERT INTO world_resources (world_id,resource_key,quantity,unit)
SELECT id,'metal',10,'unit' FROM worlds WHERE slug='evo-house'
ON DUPLICATE KEY UPDATE resource_key=VALUES(resource_key);
INSERT INTO world_resources (world_id,resource_key,quantity,unit)
SELECT id,'energy',100,'unit' FROM worlds WHERE slug='evo-house'
ON DUPLICATE KEY UPDATE resource_key=VALUES(resource_key);
