-- Chat-bot configuration: per-instance trigger registry
CREATE TABLE empyrion_chatbot_rules (
  id           TEXT PRIMARY KEY,
  instance_id  TEXT,                     -- NULL = applies to all empyrion instances
  command      TEXT NOT NULL,            -- player types "!<command>" in chat
  description  TEXT NOT NULL DEFAULT '',
  response     TEXT NOT NULL,            -- supports {playerName} {playerId} {factionId} {playfield} placeholders
  channel      TEXT NOT NULL DEFAULT 'whisper', -- whisper | global | faction
  enabled      BOOLEAN NOT NULL DEFAULT true,
  created_at   TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at   TIMESTAMPTZ NOT NULL DEFAULT now(),
  UNIQUE (instance_id, command)
);

-- Seed three default rules (global, applies to all instances)
INSERT INTO empyrion_chatbot_rules (id, instance_id, command, description, response, channel, enabled) VALUES
  ('cb_help',   NULL, 'help',     'List available commands',  'Bot commands: !help · !coords · !time', 'whisper', true),
  ('cb_coords', NULL, 'coords',   'Tell player their coords', 'Your position: {playfield} ({x},{y},{z})', 'whisper', true),
  ('cb_time',   NULL, 'time',     'Server clock',             'Server time: {now}', 'whisper', true);
